Last Updated on : 2023-02-17 03:11:21download
This topic describes how to define functions for a TuyaLink-based product.
The device model construct describes an abstraction of physical devices. It defines the characteristics and behaviors of a type of device that connects to the Tuya IoT Development Platform.
A device model defines an abstract representation of a device as a set of properties, actions, and events, which determines how a connected physical device interacts with the cloud applications.
||The property type is used to define the continuous and queryable states of a device, which can represent one or several feature parameters. A property can be read-write or read-only for data update and query. When a specific feature parameter is updated, the device can update the property accordingly. For example, a light bulb might have properties like power state and brightness.|
||The action type is used to run complex tasks. An action command is not intended to change the device property but directs the device to return a response. For example, face recognition and picture transmission.|
||The event type is used to define live notification reported by a device, which requires external sensing and processing. Events work with message subscription or rule engines to respond as per the predefined logic. For example, overheating alerts and fault alerts.|
Standard function: refers to a template library of standard data points (DP). It provides the definition of common features for more than 1,000 product categories.
Custom function: supports various feature types and data types to help you define custom features as needed.
You have created at least one TuyaLink-based product.
Log in to the Tuya IoT Development Platform. Choose a created product and click Continue to Develop.
Click the Function Definition tab.
Select the desired functions and add them.
If the standard functions cannot address your needs, you can create custom functions.
Three function types are available: property, event, and action. Choose the types that suit your product features to create custom functions.
Click Add in the Custom Functions section.
Select a function type and populate the required fields to create a custom function. The required information varies depending on function types. See the following introduction to fields regarding each function type.
The property type is used to define the continuous and queryable states of a device, which can represent one or several feature parameters. For example, a light bulb might have properties like power state and brightness.
DP Name: the name of a custom function.
Identifier: the unique identifier of a custom function.
Data Type: the data type of a property. Nine data types are available, namely value, string, date, boolean, enum, raw, struct, array, and fault.
Example for property definitions
|Value||Take the temperature which ranges from 1°C to 100°C as an example. If the reported data is 36.6°C, The definition is as follows:
|String||Take the URL of the image as an example. The definition is as follows:
|Date||Take the product update time as an example. The device data is reported and parsed by the timestamp. The definition is as follows:
|Bool||Take the switch as an example. The switch has two statuses: on and off. The definition is as follows:
|Enum||Take the run mode as an example. It includes sports mode, personal mode, and team mode. The definition is as follows:
|RAW||Take the binary code as an example. It cannot be transmitted in plaintext.
|Struct||Take geolocation as an example. It is in multiple data types.
|Array||Take the color of lights as an example. The color depends on the data.
|Fault||Take the alert as an example. You can report the specified information according to predefined conditions.
The event type is used to report live device alerts to the cloud. The reported data can include one or more output parameters. For example, overheating alerts and fault alerts.
The action type applies to complex tasks that are required to return the result to the cloud. The input and output parameters must be specified due to this request-response mechanism. For example, after a door is unlocked, the smart lock will return a message indicating the door is unlocked to the mobile app.
With the three function types, you can build a cloud-based model with a complete set of features you want to apply to a physical device. This separates a physical device from the device model so that the hardware and application development can be performed in parallel for a quick development cycle.
Proceed with device development to register your devices for cloud connectivity.
Is this page helpful?YesFeedback
Is this page helpful?YesFeedback