Custom Function

Last Updated on : 2024-06-24 09:51:12download

Product functions are the abstraction of smart device functions and are used to describe the functionalities and parameters of respective products. You can customize functions beyond the standard functions.

Functional description

  • When you add a custom function, you need to consider properties such as data point (DP), DP ID, DP name, identifier, data type, and data transfer type. For more information, see Product Functions.
  • To ensure the stable operation of your product, we recommend the total number of standard functions and custom functions be limited to 40. Otherwise, make sure to test the stability of your product.
  • Each function can be defined by different data types. The platform supports six data types, including Boolean, value, enum, fault, string, and raw.
    • Boolean, value, and enum: basic data types, applying to most functions.
    • Fault: used to define errors.
    • String and raw: used to define complex functions. You can try these two types if the other types cannot meet your needs.
  • You cannot add custom functions to a product created with a no-code solution.
  • Custom functions allow you to configure specific DPs during embedded development. You can select custom functions to suit your needs. Rules for special configurations:
    • Passive Reporting: The module can report DP data only when it receives a command. This can avoid frequent data reporting.
    • Repeated Reporting: The module can report identical DP data.
    • DP Routing: Control which protocol the cellular and Bluetooth combo module uses for DP data transmission. The following three modes are supported:
      • Not Set: Cellular network is preferred. If a cellular network is not available, Bluetooth is used.
      • Bluetooth Priority: Bluetooth is preferred. If Bluetooth is disconnected, a cellular network is used.
      • Force Bluetooth: Force the use of Bluetooth. If Bluetooth is disconnected, the app panel will display an error message.
    • Cloudless: During pairing, the SDK reads this option from the DP settings and determines whether to report the DP data only to the app, but not to the cloud.

Prerequisites

You have created at least one product. For more information, see Create Products.

Procedure

  1. Log in to the Tuya Developer Platform.

  2. In the product list, find a target product whose status is Developing, and click Develop in the Operation column.

    Custom Function
  3. Check out the custom functions that have been added to the product. Depending on your needs, you can:

    • Click Add to add more custom functions.

    • Click Delete to delete the specified custom function.

    • Click Edit to edit the specified custom function.

      Custom Function

Sample DPs

Boolean

  • Application: Applies to a binary variable that is either true or false.

  • Example: For the device switch, child lock on a heating device, fan head, and reset button of the filter cartridge for the air purifier, their DPs of Boolean type can be configured.

    Custom Function

Value

  • Application: Applies to a variable 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 be turned on or off automatically at the specified time point, you can set the reservation from 1 hour to 12 hours with a pitch of 1 hour.

      Custom Function

Enum

  • Application: Applies to a finite collection of custom values. After you enter an enum value, press the ENTER button to confirm.

  • Example:

    • Working level: low, medium, and high.
    • Mode: comfort mode, sleep mode, smart mode, and energy saving mode.
    • Color: red, blue, green, and black.

    An enum value can only contain lowercase letters, numbers, and underscores. After entering a value, press the ENTER button to confirm. Then, the enum value is automatically generated. The code of enum values starts from 0. An enum value is transmitted by its code. An enum value must not exceed 15 characters. Up to 10 enum values can be created.

    Custom Function

Fault

  • Application: Applies to fault reporting and counting.

  • Example: temperature sensor faults, motor faults, and high temperature problems.

    Faults adopt the bitmap data format. You can define multiple faults. The fault function only supports data reporting, so you can only choose Report Only as the data transfer type.

    Custom Function

String

  • Application: Applies to DP data transmitted in string format. If the above-mentioned four data types cannot meet your definition of product functions, you can configure DPs to transmit data in the form of strings.

  • Things to note: The length of a string must not exceed 255 bytes.

    Custom Function

Raw

  • Application: Applies to raw data that is passed through in the binary format. This data type is not recommended. You can use the raw data type to deal with complex functions when other function types cannot satisfy your requirements.

  • Things to note: The length of raw data must not exceed 255 bytes.

    Custom Function

Next steps

After setting the custom functions, you can:

FAQs

For more information, see Custom Function FAQs.