|
3 | 3 | * TOC |
4 | 4 | {:toc} |
5 | 5 |
|
6 | | -## Overview |
| 6 | +Tuya is an IoT platform that enables device manufacturers and solution providers to connect, manage, and control smart devices through the Tuya Cloud. |
7 | 7 |
|
8 | | -Tuya is a cloud platform that connects a range of devices via the IoT. After integrating Tuya with the ThingsBoard, you can connect, manage, communicate, process and visualize data from your devices in the ThingsBoard IoT platform. |
| 8 | +The Tuya Cloud Integration in ThingsBoard allows you to: |
| 9 | +- Connect Tuya-managed devices to ThingsBoard |
| 10 | +- Receive telemetry and device state updates |
| 11 | +- Send control commands from ThingsBoard to Tuya devices |
| 12 | +- Visualize device data and manage devices centrally |
9 | 13 |
|
10 | | -## Tuya Integration Tutorial |
| 14 | +This guide describes how to configure an end-to-end integration using a real device - **Tuya Smart Plug**. |
| 15 | +Also, you can use a [virtual Tuya device](https://developer.tuya.com/en/docs/iot/manage-virtual-devices?id=Ka4725tiyfhg0){:target="_blank"} for testing. |
11 | 16 |
|
12 | | -In this tutorial we will use a real device - Smart Plug. |
| 17 | +## Prerequisites |
13 | 18 |
|
14 | | -Also, you can use a [**virtual device**](https://developer.tuya.com/en/docs/iot/manage-virtual-devices?id=Ka4725tiyfhg0). Virtual devices help you to perform cloud development without an actual IoT device. |
| 19 | +Before starting, ensure you have: |
| 20 | +- A ThingsBoard account with permission to create integrations |
| 21 | +- A Tuya IoT Platform account |
| 22 | +- At least one Tuya device (physical or virtual) |
| 23 | +- Tuya Smart App installed and logged in |
15 | 24 |
|
16 | | -### Prerequisites |
| 25 | +## Install smart device control application |
17 | 26 |
|
18 | 27 | The first step is to install the smart device control application (Smart Life, Tuya Smart, or other) on your mobile device and register your Smart Plug device in the application. |
19 | 28 |
|
20 | 29 | {% include images-gallery.html imageCollection="tuya-application-add-device" %} |
21 | 30 |
|
22 | | -### Tuya setup |
| 31 | +## Tuya cloud configuration |
23 | 32 |
|
24 | | -#### Create cloud project |
| 33 | +### Create cloud project |
25 | 34 |
|
26 | | -The next step is to register an account on [Tuya](https://www.tuya.com/) and create cloud project. |
| 35 | +The next step is to register an account on [Tuya](https://www.tuya.com/){:target="_blank"} and create cloud project. |
| 36 | +- Go to the **Cloud** tab ⇾ **Project Management**. Click the **Create Cloud Project** button. |
| 37 | +- In a pop-up window, fill required fields and click "Create". |
| 38 | +- Make additional settings in the **Authorize API Services** window and click **Authorize**. |
| 39 | +- Now your cloud project is created. In this window, remember the **Access ID/Client ID** and **Access Secret/Client Secret** values. These values will be needed during the Tuya Integration setup. |
27 | 40 |
|
28 | | -{% include images-gallery.html imageCollection="tuya-create-cloud-project" showListImageTitles="true" %} |
29 | | - |
30 | | -#### Enable Tuya message service |
| 41 | +### Enable Tuya message service |
31 | 42 |
|
32 | 43 | Enable the message service to timely receive messages about device registration, data reporting, and status change. |
| 44 | +- Go to the **Message Service** tab. |
| 45 | +- Toggle to enable Message Service. |
| 46 | +- In the pop-up window, set up the messaging service. Configure the settings for **Message Service Type** and **Alert Contact**. Click **Ok**. |
| 47 | +- Message Service enabled. |
33 | 48 |
|
34 | | -{% include images-gallery.html imageCollection="tuya-message-service-enable" showListImageTitles="true" %} |
35 | | - |
36 | | -#### Link Tuya App Account |
| 49 | +### Link Tuya App account |
37 | 50 |
|
38 | 51 | You need to link your devices to this project using your Smart Life app account. |
| 52 | +- Go to **Cloud** tab -> **Project management**. Select your project. |
| 53 | +- Navigate to the **Devices** tab -> select the **Link App Account** tab. Click **Add App Account**. |
| 54 | +- Select Tuya Account Authorization option. |
| 55 | +- Scan the QR code with Smart Life App to authorize. |
| 56 | +- In the pop-up window, select Automatic Link and Click **Ok**. |
| 57 | +- Now your devices under the mobile app account have been added to the project. |
| 58 | +- Navigate to the "All Devices" tab. You can see your device added to the project. |
39 | 59 |
|
40 | | -{% include images-gallery.html imageCollection="tuya-add-smart-life-app" showListImageTitles="true" %} |
41 | | - |
42 | | -<br> |
43 | | -**Note:** |
44 | | -<br> |
45 | | -Make sure you enabled Messaging rule (filter) to receive uplinks. The very basic filter (statusReport) should be sufficient for testing purposes |
| 60 | +Make sure you enabled Messaging rule (filter) to receive uplinks. The very basic filter (statusReport) should be sufficient for testing purposes: |
46 | 61 |
|
47 | 62 | {% include images-gallery.html imageCollection="tuya-enable-rules-environment" showListImageTitles="true" %} |
48 | 63 |
|
49 | | -## Tuya Integration Configuration |
| 64 | +## ThingsBoard integration configuration |
50 | 65 |
|
51 | | -### Uplink Converter |
| 66 | +Let's move on to setting up the integration between the ThingsBoard platform and Tuya. |
52 | 67 |
|
53 | | -Before setting up a **Tuya integration**, you need to create an **Uplink Converter** which is a script for parsing and transforming the data received by Tuya integration to a format that ThingsBoard can consume. |
| 68 | +<b><font size="4">1. Basic settings</font></b> |
54 | 69 |
|
55 | | -To create an **Uplink Converter**, go to the **Data Converters** section and click **Add new data converter —> Create new converter**, name it **"Tuya Uplink Converter"** and select type **Uplink**. Use debug mode for now. |
| 70 | +- Log in to your ThingsBoard account. |
| 71 | +- Go to the **Integrations center** ⇾ **Integrations**. |
| 72 | +- Click **+** (**plus**) button. |
| 73 | +- From the list, select **Tuya** integration type. |
| 74 | +- If you'd like to monitor events and troubleshoot, enable **debug mode**. |
| 75 | + > Enabling debug mode allows you to track events, states, and potential errors related to the execution of . This greatly simplifies development and troubleshooting. |
| 76 | +- Click **Next**. |
56 | 77 |
|
57 | | -{% assign feature = "integrations" %}{% include templates/debug-mode.md %} |
| 78 | +<b><font size="4">2. Uplink data converter</font></b> |
58 | 79 |
|
59 | | -**Choose device payload type to for decoder configuration:** |
| 80 | +Uplink is necessary in order to convert the incoming data from the device into the required format for displaying them in ThingsBoard. |
| 81 | +- Enter a name for the converter. It must be unique. |
| 82 | +- To view the events, enable debug mode. |
| 83 | +- In the **Main decoding configuration** section, provide your own script or use the script below. |
60 | 84 |
|
61 | 85 | {% include templates/tbel-vs-js.md %} |
62 | 86 |
|
63 | 87 | {% capture tuyauplink %} |
64 | 88 | TBEL<small>Recommended</small>%,%accessToken%,%templates/integration/tuya/tuya-uplink-tbel.md%br% |
65 | 89 | JavaScript<small></small>%,%anonymous%,%templates/integration/tuya/tuya-uplink-java.md{% endcapture %} |
66 | | - |
67 | 90 | {% include content-toggle.liquid content-toggle-id="tuyauplink" toggle-spec=tuyauplink %} |
68 | 91 |
|
69 | | -### Downlink Converter |
| 92 | +- Once the uplink converter is set up, click **Next**. |
70 | 93 |
|
71 | | -The Downlink converter transforming outgoing RPC message and then the Integration sends it to your device. |
| 94 | +<b><font size="4">3. Downlink data converter</font></b> |
72 | 95 |
|
73 | | -Create another converter with the name **"Tuya Downlink Converter"** and type **Downlink**. To see events - enable Debug. |
| 96 | +The Downlink converter transforming outgoing RPC message and then the Integration sends it to your device. |
| 97 | +You can use our example of Downlink Converter, or write your own according to your configuration: |
74 | 98 |
|
75 | 99 | {% capture tuyadownlink %} |
76 | 100 | TBEL<small>Recommended</small>%,%accessToken%,%templates/integration/tuya/tuya-downlink-tbel.md%br% |
77 | 101 | JavaScript<small></small>%,%anonymous%,%templates/integration/tuya/tuya-downlink-java.md{% endcapture %} |
78 | | - |
79 | 102 | {% include content-toggle.liquid content-toggle-id="tuyadownlink" toggle-spec=tuyadownlink %} |
80 | 103 |
|
81 | | -### Tuya Integration Setup |
| 104 | +- Click **Next**. |
82 | 105 |
|
83 | | -Go to **Integrations** section and click Add new integration button. Name it **Tuya Integration**, select type **Tuya**; |
84 | | - |
85 | | -{% if docsPrefix == "pe/" %} |
86 | | - |
87 | | -{% endif %} |
88 | | -{% if docsPrefix contains "paas/" %} |
89 | | - |
90 | | -{% endif %} |
91 | | - |
92 | | -In this step, you can select the recently created **Tuya Uplink Converter** or create a new uplink data converter; |
93 | | - |
94 | | -{% if docsPrefix == "pe/" %} |
95 | | - |
96 | | -{% endif %} |
97 | | -{% if docsPrefix contains "paas/" %} |
98 | | - |
99 | | -{% endif %} |
100 | | - |
101 | | -Add **Tuya Downlink Converter** to the integration or create a new downlink data converter; |
102 | | - |
103 | | -{% if docsPrefix == "pe/" %} |
104 | | - |
105 | | -{% endif %} |
106 | | -{% if docsPrefix contains "paas/" %} |
107 | | - |
108 | | -{% endif %} |
| 106 | +<b><font size="4">4. Connection</font></b> |
109 | 107 |
|
110 | 108 | In the last step, fill in the following fields: |
111 | | - |
112 | 109 | - **Region** - specify your region; |
| 110 | +- **Environment**: |
| 111 | + - Choose **PROD** for real devices. |
| 112 | + - Select **TEST** if you want to connect a **virtual device** to Thingsboard and test its operation before you buy it. |
| 113 | +- **Access Id** and **Access Key** is an authorization certificate distributed by Tuya. Paste [previously copied Access Id and Access Key](#create-cloud-project) into the integration. |
| 114 | +- Click **Add** to create an integration. |
113 | 115 |
|
114 | | -- **Environment:** choose **PROD** or **TEST**. Choose **PROD** for real devices. Select **TEST** if you want to connect a [**virtual device**](https://developer.tuya.com/en/docs/iot/manage-virtual-devices?id=Ka4725tiyfhg0) to Thingsboard and test its operation before you buy it. |
115 | | - |
116 | | -- **Access Id** and **Access Key** is an authorization certificate distributed by Tuya. Paste previously copied **Access Id** and **Access Key** into the integration. |
117 | | - |
118 | | -Click "Add" to create an integration. |
119 | | - |
120 | | -{% if docsPrefix == "pe/" %} |
121 | | - |
122 | | -{% endif %} |
123 | | -{% if docsPrefix contains "paas/" %} |
124 | | - |
125 | | -{% endif %} |
126 | | - |
127 | | -### Rule Chain configuration |
| 116 | +## Rule Chain configuration |
128 | 117 |
|
129 | 118 | When integration configured and ready to use, we need to go to **Rule Chains**, choose **"Root Rule Chain"** and here create rule node **Integration Downlink**. Input some name here, choose earlier created Tuya integration, and tap **Add**. |
130 | 119 |
|
131 | | -{% if docsPrefix == "pe/" %} |
132 | | - |
133 | | -{% endif %} |
134 | | -{% if docsPrefix contains "paas/" %} |
135 | 120 |  |
136 | | -{% endif %} |
137 | 121 |
|
138 | | -After these steps, we need to tap on a right grey circle of rule node **message type switch** and drag this circle to left side of **Integration Downlink**. In pop-up window add **"RPC Request to Device"** linl, and tap "Add". Save the Root Rule Chain. |
| 122 | +After these steps, we need to tap on a right grey circle of rule node **message type switch** and drag this circle to left side of **Integration Downlink**. In pop-up window add **"RPC Request to Device"** link, and tap **Add**. **Save** the Root Rule Chain. |
139 | 123 |
|
140 | | -{% if docsPrefix == "pe/" %} |
141 | 124 |  |
142 | | -{% endif %} |
143 | | -{% if docsPrefix contains "paas/" %} |
144 | | - |
145 | | -{% endif %} |
146 | 125 |
|
147 | | -### Uplink message |
| 126 | +## Uplink message |
148 | 127 |
|
149 | | -Once ThingsBoard **Tuya Integration** has been created, you must disconnect Smart Plug from power and reconnect. The device will send an uplink message with telemetry and attributes to the integration |
| 128 | +Once ThingsBoard Tuya Integration has been created, you must disconnect Smart Plug from power and reconnect. The device will send an uplink message with telemetry and attributes to the integration. |
150 | 129 |
|
151 | | -Go to **Device Groups** -> **All** you should find your device provisioned by the Integration. In my case it is - **SmartPlug268970**. |
| 130 | +Go to **Entities ⇾ Devices**. You should find your device provisioned by the Integration. |
152 | 131 |
|
153 | | -{% if docsPrefix == "pe/" %} |
154 | | - |
155 | | -{% endif %} |
156 | | -{% if docsPrefix contains "paas/" %} |
157 | | - |
158 | | -{% endif %} |
| 132 | +In my case it is - **SmartPlug268970**. |
159 | 133 |
|
160 | | -### Tuya Smart Plug Dashboard |
| 134 | +## Tuya Smart Plug Dashboard |
161 | 135 |
|
162 | 136 | To visualize the Smart Plug data and test RPC commands, we will create the **Tuya Smart Plug** dashboard. |
| 137 | +- Download the [tuya_smart_plug_dashboard.json](/docs/user-guide/resources/tuya_smart_plug_dashboard.json){:target="_blank" download="tuya_smart_plug_dashboard.json"} file. |
| 138 | +- Go to the **Dashboards**. |
| 139 | +- Click the **+** (**plus**) icon at the upper right corner of the table, and select **Import dashboard**. |
| 140 | +- Drag the previously downloaded JSON file into the window. |
| 141 | +- Tap **Import**. |
163 | 142 |
|
164 | | -- Download the [**tuya_smart_plug_dashboard.json**](/docs/user-guide/resources/tuya_smart_plug_dashboard.json) file |
165 | | -- Go to the **Dashboard groups** tab. Create dashboard group - **Smart Plug** and go to it. |
166 | | -- To import this JSON file, click the `import` button at the upper right corner of the dashboard group page and drag the previously downloaded file into the window. Tap **Import**. |
167 | | - |
168 | | -{% if docsPrefix == "pe/" %} |
169 | | - |
170 | | -{% endif %} |
171 | | -{% if docsPrefix contains "paas/" %} |
172 | 143 |  |
173 | | -{% endif %} |
174 | 144 |
|
175 | | -- Open the **Tuya Smart Plug** dashboard |
176 | | -- **Enter edit mode**, click **Entity aliases** button and add your device to **smartPlug** alias |
| 145 | +- Open the **Tuya Smart Plug** dashboard. |
| 146 | +- Enter **Edit mode**, and update **Entity aliases** - specify your device as target device in the **smartPlug** alias |
177 | 147 |
|
178 | | -{% if docsPrefix == "pe/" %} |
179 | 148 |  |
180 | | -{% endif %} |
181 | | -{% if docsPrefix contains "paas/" %} |
182 | | - |
183 | | -{% endif %} |
184 | 149 |
|
185 | 150 | {% capture difference %} |
186 | | -**NOTE:** |
187 | | -<br> |
188 | | -time series data keys of your device may differ from those presented. If necessary, you will need to replace them, according to the documentation for your device (for each widget). |
| 151 | +**NOTE:** Time series data keys of your device may differ from those presented. If necessary, you will need to replace them, according to the documentation for your device (for each widget). |
189 | 152 | {% endcapture %} |
190 | 153 | {% include templates/info-banner.md content=difference %} |
191 | 154 |
|
192 | | -{% if docsPrefix == "pe/" %} |
193 | | - |
194 | | -{% endif %} |
195 | | -{% if docsPrefix contains "paas/" %} |
196 | 155 |  |
197 | | -{% endif %} |
198 | 156 |
|
199 | 157 | <br> |
200 | 158 | If you have everything configured correctly, you will see Smart Plug status light (on/off) and telemetry for the last hour: voltage, power, and current. |
201 | 159 |
|
202 | | -{% if docsPrefix == "pe/" %} |
203 | 160 |  |
204 | | -{% endif %} |
205 | | -{% if docsPrefix contains "paas/" %} |
206 | | - |
207 | | -{% endif %} |
208 | 161 |
|
209 | 162 | Smart Plug status light is green. Try to switch off the Smart Plug by clicking on the **On/Off Round switch** |
210 | 163 |
|
211 | | -{% if docsPrefix == "pe/" %} |
212 | | - |
213 | | -{% endif %} |
214 | | -{% if docsPrefix contains "paas/" %} |
215 | 164 |  |
216 | | -{% endif %} |
217 | 165 |
|
218 | 166 | The Smart Plug status indicator turns grey. Power consumption stops. |
219 | 167 |
|
220 | | -{% if docsPrefix == "pe/" %} |
221 | | - |
222 | | -{% endif %} |
223 | | -{% if docsPrefix contains "paas/" %} |
224 | 168 |  |
225 | | -{% endif %} |
226 | 169 |
|
227 | 170 | ## Next steps |
228 | 171 |
|
|
0 commit comments