Contact Us
Log In

Custom Function

Last Updated on : 2022-09-21 03:47:56download

You can customize functions beyond the standard functions. When you create custom functions, you need to set the data point (DP) ID, identifier, data type, data transfer type, and more. This topic describes DPs and data types for TuyaOS products developed by a custom solution. For TuyaLink-based products, see Function Definition.

Note: To ensure the stability of products, do not add more than 40 functions. Otherwise, test the product stability.

Data point

The data point (DP) is the abstraction of a smart device function, describing product functions and parameters.

  • DP ID: the identification of a data point. The DP ID is used for DP data transmission between the device and the cloud.

  • DP name: the name of a custom function.

  • Identifier: the code value of a data point. It is used for displaying the DP name in multi-language on the app. Support letters, numbers, and underscores (_), starting with a letter.

  • Data type:

    Type Parameter name Description Example
    Bool bool Represent binary variable value that is either true or false. On/off control. Turn a device on or off.
    Value value Apply to the data that can be linearly adjusted. Adjust the temperature, ranging from 20°C to 40°C.
    Enum enum A custom finite set of values. Change the working level in terms of high, medium, and low.
    Fault fault Used to report DP failure. Simultaneous reporting of multiple faults is supported. Faults occur in the temperature sensor, motor, and more.
    String string Transmit the data as a string. -
    Raw Raw Transmit the data in a raw binary format. -
  • Data transfer type:

    • Send and report: two-way data transmission between the device and the cloud.
    • Report only: one-way data transmission. Data can only be reported from the device.
    • Send only: one-way data transmission. Data can only be sent from the cloud.

Data type

You can define a function in varied data types. Six data types are available, namely bool, value, enum, fault, string, and raw.

  • Bool, value, and enum are the three basic types, and most of the functions can be defined by them.
  • Fault is specified for fault statistics in the backend.
  • The string type and the raw type are the advanced types for defining complicated functions. These two types are recommended if the other four types cannot meet your needs.


  • Application: represents binary variable value (true or false).

  • For example, the device switch, child lock on heating device, fan head, resetting filter cartridge for the air purifier can be defined in the bool type.

    Custom Function


  • Application: represents data that can be linearly adjusted.

  • Example:

    • Temperature adjustment. For device temperature ranging from 20°C to 40°C with a pitch of 1, it indicates that the device temperature can range from 20°C to 40°C. With each operation, the temperature increases or decreases by 1°C.
    • Reservation. For the scenario that a device with a 12-hour timer is set to turn on or off automatically at a specified time, you can set the reservation from 1 hour to 12 hours with the interval of 1 hour.
    Custom Function


  • Application: represents custom finite value set. Each time you enter an enum value, press the Enter key to generate a value.

  • Example:

    • Working levels: low, middle and high.
    • Modes: comfort, sleep, smart, and power saving.
    • Colors: red, blue, green, and black.

    Note: when editing function points, you can enter letters, numbers, and underscores (_). After you press the Enter key, the enum value will be automatically generated. Code of enum values starts from 0, and data is transferred in enum code during hardware integration testing. The length of each enum value cannot exceed 15 characters, and a maximum of 10 enum values can be defined.

    Custom Function


  • Application: specified for fault report and statistics. Later, this function will be used for statistics.

  • For example, faults occur in the temperature sensor, motor, and more.

  • Note: fault data is in the format of bitmap, so defining multiple faults is available. The fault type only supports data reporting, so you can only select Report Only for the data transfer type.

    Custom Function


  • Application: indicates data transfer in string type. If you cannot define a function in the above four data types, you can select the string type as the data transfer type.

  • Note: the length of a single string type cannot exceed 255 bytes.

    Custom Function


  • Application: indicates data transfer in a raw binary format. Generally, it is recommended to use raw data transfer when the other five types cannot cope with complicated product functions.

  • Note: the length of raw data cannot exceed 255 bytes.

    Custom Function


For more information, see Custom Functions FAQs.