Develop Smart Switch Module

Last Updated on : 2024-06-17 10:54:52download

To develop a product on the Tuya Developer Platform, you need to define product functions, select and customize device panels, develop embedded firmware, and perform a production test.

Step 1: Define functions

The product function is broken down into three types, standard functions, custom functions, and advanced functions.

A product function is the abstraction of a feature that is provided by a smart device. You can use product functions to describe the features and parameters of smart devices. After the product function is defined, the platform will generate a cloud-based device model that serves as a virtual representation of your physical device.

Data point (DP) data type

The platform allows you to define functions with six data types, including Boolean, value, enum, fault, string, and raw. For more information, see Sample DPs.

DP IDs 1 to 6: switch

Data type Value range
Boolean
  • 0: Off
  • 1: On

DP IDs 7 to 12: countdown

Users specify a time delay. After the timer is done, the device automatically turns on or off based on its current on/off state. If the switch is on, it can be set to automatically turn off. If the switch is off, it can be set to automatically turn on. If the switch is interrupted by manual on/off control when the timer is running, the countdown timer will be canceled.

Data type Value range
Value 0 to 86400, in seconds.

The valid values range from 0 to 43200 for the Zigbee protocol.

DP ID 14: restart status

Set the switch status after power failure. If a device has multiple switch channels, this DP status applies to all channels.

Data type Value range
Enumeration
  • off: The device will be off when power is restored.
  • on: The device will be on when power is restored.
  • memory: The device resumes its previous state when power is restored.

DP ID 17: cycle timing (string)

A cyclic timer allows users to cycle a device between on and off during a set time period and specify the recurring day(s) of a week. By default, the device is turned on when the task starts and is turned off when the task ends.

This provides a convenient way to automate routines such as for cyclic irrigation, pet feeding, and control of lighting scenarios.

No. Field Length (byte) Property
1 Switch + channel ID 1
  • Bit 0: indicates the on/off state of the node.
  • Bit 1 to bit 7: indicates the channel to which the node is applied.
For example, 0x03 is 0000 0011 in binary. 1 represents the ON state.
2 Day of week 1 Specifies the recurring day(s). If a bit is set to 1, it means that the task will recur weekly on this specified day. The following table details each field.
3 Start time 2 Valid values: 0 to 1439, in minutes.
4 End time 2 Valid values: 0 to 1439, in minutes.
5 ON state duration 2 Valid values: 1 to 1440, in minutes.
6 OFF state duration 2 Valid values: 1 to 1440, in minutes.

Description of recurring day(s)

If all the bits are set to 0, it indicates a one-time task. If a bit is set to 1, it indicates the task recurs on that day every week. For example, 0x42 means that the task takes effect on Saturday and Monday. Note that the task switch must be turned on.

Reserved Saturday Friday Thursday Wednesday Tuesday Monday Sunday
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0

DP ID 18: random timing (string)

Users can schedule a task to turn on and off their devices randomly during the set time period. By default, the device is on when the task starts and is off when the task ends.
When users go out for a long time, random timing can be used to turn the lights on or off just as if someone was at home, in order to deter burglars.

No. Field Length (byte) Property
1 Switch + channel ID 1
  • Bit 0: indicates the on/off state of the node.
  • Bit 1 to bit 7: indicates the channel to which the node is applied.
For example, 0x03 is 0000 0011 in binary. 1 represents the ON state.
2 Day of week 1 Specifies the recurring day(s). If a bit is set to 1, it means that the task will recur weekly on this specified day. The following table details each field.
3 Start time 2 Valid values: 0 to 1439, in minutes.
4 End time 2 Valid values: 0 to 1439, in minutes.

Description of recurring day(s)

If all the bits are set to 0, it indicates a one-time task. If a bit is set to 1, it indicates the task recurs on that day every week. For example, 0x42 means that the task takes effect on Saturday and Monday. Note that the task switch must be turned on.

Reserved Saturday Friday Thursday Wednesday Tuesday Monday Sunday
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0

DP ID 19: inching switch (string)

The inching switch can enable a device to be turned off automatically after it is on for a specified period, regardless of how it is activated.
Inching switches are widely used in public places such as corridors and stairways. For example, if an inching in-wall switch is delayed for one minute to turn off and it is connected to a corridor light, users only need to turn on the light whenever they pass through the corridor. The switch automatically turns the light off one minute later, relieving users from setting a countdown timer or manually turning the light off.

No. Field Length (byte) Property
1 Switch + channel ID 1
  • Bit 0: indicates the on/off state.
  • Bit 1 to bit 7: indicates the channel ID.
2 Inching duration 2 Valid values: 1 to 65535, in seconds.

DP IDs 20 to 28: energy metering

DP Data type Value range
Add electricity Value 0 to 50000, in kWh.
Current Value 0 to 30000, in mA.
Voltage Value 0 to 5000, in V.
Power Value 0 to 50000, in W.
Test bit Value 0 to 5.
Voltage calibration factor Value 0 to 1000000
Current calibration factor Value 0 to 1000000
Power calibration factor Value 0 to 1000000
Electricity calibration factor Value 0 to 1000000

Energy metering is available only after you subscribe to the metering feature.

DP ID 47: switch type

Set the type of external switch connected to the device. If a device has multiple switch channels, this DP status applies to all channels.

Data type Value range
Enumeration
  • flip: rocker switch. Rocker switches house a button for operation that can be pressed on either end like a seesaw to change the device status.
  • sync: rocker switch. The switch ON/OFF position is in sync with the load status.
  • button: self-recovery switch. The switch automatically rebounds after being pressed and released, and the status is switched once.

DP ID 48: switch interlock (raw)

Users can set 2-gang or multi-gang switches to be interlocked. Only one of the channels can be enabled, while the other channels are automatically disabled. The switch can work properly to change the rotation direction of a motor. Channels cannot be enabled simultaneously, but can be disabled simultaneously.

No. Field Length (byte) Property
1 Interlocking group 1 2
  • Bit 0 to bit 15 correspond to channels 1 to 16 respectively. 1 means the specified channel is interlocked and 0 means the specified channel is not interlocked.
  • For example, 0000 0000 0000 0110 means that channels 2 and 3 are interlocked, while channels 1 and 4 can be turned on or off as expected.
2 Interlocking group 2 2 Same as above.
3 Interlocking group 3 2 Same as above.
4 Interlocking group 4 2 Same as above.

One switch can be added to only one interlocking group. Settings are overwritten by the last operation.

DP IDs 49 to 50: RF433 remote control (raw)

Users can add an external decoding circuit and use the module for decoding, helping implement local remote control pairing and app pairing. In addition, users can set up the functions of the remote control buttons and manage them on the app.

  • Local pairing: Under normal working conditions, continuously press the master control button three times to enter remote pairing.
  • Local unbinding: Under normal working conditions, continuously press the master control button eight times to clear all paired remote controls.
  • App pairing/unbinding: Settings > RF remote control settings.

Users can perform four types of actions on remote control buttons, including no action, disable, enable, and flip. After pairing, the flip mode is used by default, which can be modified on the app.

No. Field Length (byte) Property
Add a remote control 2 to 4
  • 1#: 1 byte. Commands are as follows: 1: Add a remote control. 0: Exit. 2: The remote control is added.
  • 2#, 3#, and 4#: 3 bytes, the address code of the specified remote control.
List of remote controls N
  • 1#, 2#, and 3#: 3 bytes, the address code of the specified remote control.
  • 4# to 7#: 4 bytes. State: every 2 bits correspond to 4 states. 00: no action. 01: disabled. 10: enabled. 11: flip. Correspond to 1 to 16-gang switches. For example, bits 0 to 1 corresponds to the 4 states of switch 1.
  • The list of up to 30 remote controls is stored in order, with a maximum size of 210 bytes. That is, 30 × 7 = 210 bytes.

The list of remote controls is delivered in one packet.

DP ID 209: cycle timing (raw)

A cyclic timer allows users to cycle a device between on and off during a set time period and specify the recurring day(s) of a week. By default, the device is turned on when the task starts and is turned off when the task ends.

This provides a convenient way to automate routines such as for cyclic irrigation, pet feeding, and control of lighting scenarios.

No. Field Length (byte) Property
1 Version number 1 /
2 Byte length 1 /
3 Switch + channel ID 1
  • Bit 0: indicates the on/off state of the node.
  • Bit 1 to bit 7: indicates the channel to which the node is applied.
For example, 0x03 is 0000 0011 in binary. 1 represents the ON state.
4 Day of week 1 Specifies the recurring day(s). If a bit is set to 1, it means that the task will recur weekly on this specified day. The following table details each field.
5 Start time 2 Valid values: 0 to 1439, in minutes.
6 End time 2 Valid values: 0 to 1439, in minutes.
7 ON state duration 2 Valid values: 1 to 1440, in minutes.
8 OFF state duration 2 Valid values: 1 to 1440, in minutes.

Description of recurring day(s)

If all the bits are set to 0, it indicates a one-time task. If a bit is set to 1, it indicates the task recurs on that day every week. For example, 0x42 means that the task takes effect on Saturday and Monday. Note that the task switch must be turned on.

Reserved Saturday Friday Thursday Wednesday Tuesday Monday Sunday
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0

DP ID 210: random timing (raw)

Users can schedule a task to turn on and off their devices randomly during the set time period. By default, the device is on when the task starts and is off when the task ends.

When users go out for a long time, random timing can be used to turn the lights on or off just as if someone was at home, in order to deter burglars.

No. Field Length (byte) Property
1 Version number 1 /
2 Byte length 1 /
3 Switch + channel ID 1
  • Bit 0: indicates the on/off state of the node.
  • Bit 1 to bit 7: indicates the channel to which the node is applied.
For example, 0x03 is 0000 0011 in binary. 1 represents the ON state.
4 Day of week 1 Specifies the recurring day(s). If a bit is set to 1, it means that the task will recur weekly on this specified day. The following table details each field.
5 Start time 2 Valid values: 0 to 1439, in minutes.
6 End time 2 Valid values: 0 to 1439, in minutes.

Description of recurring day(s)

If all the bits are set to 0, it indicates a one-time task. If a bit is set to 1, it indicates the task recurs on that day every week. For example, 0x42 means that the task takes effect on Saturday and Monday. Note that the task switch must be turned on.

Reserved Saturday Friday Thursday Wednesday Tuesday Monday Sunday
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0

Custom functions

You can customize functions beyond the standard functions. For more information, see Custom Function.

Advanced functions

Advanced functions include cloud timing and jumping page. For more information, see Advanced Function.

  • Cloud timing: allows you to implement the schedule feature without embedded development.
  • Jumping page: enables navigating to another web page, such as an online store and user guide.

Step 2: Configure a panel

After the function definition step, you can configure a favorite app control panel for the product. A panel is a GUI-based program that runs on top of a mobile app to control smart products. For more information about panel configurations and development tutorials, see Design App UI and Panel Development.

Step 3: Design hardware

Hardware development consists of hardware design and embedded development. Tuya provides a no-code development method for some electrical products. You can develop firmware simply by editing the parameters without coding. Moreover, you can implement custom development based on the MCU SDK or TuyaOS as needed.

Generic design

No. Design type
1 Power Design
2 Compliance Design for Electrical Product

SoC solution

No. Wireless protocol Number of switch channels Power supply type Recommended module
1 Wi-Fi and Bluetooth Low Energy (LE) combo 1- to 4-gang smart switch module With neutral CB2S, CBU, and CBU-IPEX
2 Zigbee 1- to 4-gang smart switch module With neutral ZT2S, ZTU, and ZTU-IPEX
3 Zigbee 1- to 3-gang smart switch module Without neutral ZT2S, ZTU, and ZTU-IPEX
4 Bluetooth mesh 1- to 4-gang smart switch module With neutral BT2S, BTU, and BTU-IPEX

Contact Tuya’s account manager to request the open source hardware materials.

Step 4: Perform embedded development

Embedded development is broken down into SoC-based no-code development, MCU SDK development, and TuyaOS-based SDK development.

No-code development

With no-code development, you can edit the configuration parameters to generate the firmware. For more information, see the prompts on the platform.

MCU SDK

As one of the most popular methods, the MCU integration solution enables products with built-in microcontrollers to connect to the cloud and become connected. Tuya provides one-stop services including network modules, mobile apps, and cloud services, to help you easily build an IoT-enabled product. With Tuya’s MCU SDK, all-in-one mobile apps, and control panels, you can focus on application development simply, connect your product to the Tuya Developer Platform easily, and benefit from the cloud services quickly.

For more information, see MCU SDK Development.

Smart switches can be developed based on multiple protocols, including Zigbee, Wi-Fi and Bluetooth combo, and Bluetooth mesh. For more information, see the following documentation.

TuyaOS

Built on top of RTOS, Linux, and Non-OS, TuyaOS is a distributed and platform-agnostic IoT operating system.

With a standard kernel at the core, TuyaOS is designed to tackle the heterogeneity of platforms, systems, and protocols in order to enable quick and reliable integration, interconnection, and interoperability.

The tiered and plug-and-play architecture design allows you to quickly tailor a solution based on your hardware resources, hence reducing the cost of development with high cost performance. The efficient remote procedure call (RPC) mechanism and proprietary data point (DP) protocols make communication across protocols possible and easy.

Specifically, the following types of devices can be connected based on this solution:

Step 5: Configure the product

Product configuration helps you set and manage different features in one place, including firmware updates, multilingual support, device notification, device pairing, scene linkage, quick toggle, knowledge base, and product manual. These features can help you distribute products worldwide and improve user experiences with continuous iteration. The feature can take effect immediately after you finish the configuration without hardware replacement.

Take care of the multilingual support, device pairing, and scene linkage, which require product- and market-specific configuration and management.

Develop Smart Switch Module

Develop Smart Switch Module

For more information, see the following documentation.

Step 6: Flash firmware and authorize chip

Flash the device with the firmware and Tuya’s license to connect the device to the cloud. Tuya provides a variety of flashing and authorization methods for you to choose from according to different development stages.

Step 7: Test the product

Before your product can be released on the Tuya Developer Platform, you must submit a product test report. To test the product, you can use Tuya’s Cloud Test app or perform the test by yourself.

Cloud Test app

To help you quickly identify issues for troubleshooting, the Cloud Test app enables integrated testing on hardware functionalities and data interaction in terms of various test modes. For more information, see Cloud Test App.

Autonomous test

Use your own test plan to complete product functionality testing. Make sure that all product functionalities are available, including but not limited to device pairing, device control, and firmware OTA update.

Step 8: Release the product

After you submit the test report, you can release your product on the Tuya Developer Platform.

Next steps

Pass certification

To roll out your product in target markets, you need to get your product certified for each market’s regulations. By virtue of rich experience in smart product development, Tuya provides a set of product certification solutions. You can choose among these solutions to meet your product category and certification requirements. For more information, see Product Certificate.