Control LIDL (Tuya Smart) IOT devices via the LIDL (Tuya Smart) Gateway (ZigBee)
Prerequisite for this flow are a developer account at Tuya Smart For this flow, 3 pieces of information are needed.
- client_ID
- client_Secret
- device_ID
You get this data when you create an account at https://auth.tuya.com/. A good tutorial can be found everywhere on the net or here https://www.simon42.com/homebridge-smart-life/.
After you have a Client_ID and Client_Secret you have to register for the API service.
You should book the following API products for free
- Smart Home Devices Management
- Authorization
- Smart Home Family Management
- Smart Home Data Service
- Beta APIs
Afterwards you can get all information about your devices via the API Explorer. Go to https://iot.tuya.com/cloud/explorer select "Get device details" and enter your device_id of one of your devices. Now select the Data Center of your region and click on the "Submit Request" button.
All data needed for this flow can be found here.
client_ID and the device_ID are stored in the two inject nodes. The client_Secret is stored as secret key in hmac node.
[{"id":"d110bfa2.b69288","type":"tab","label":"Lidl Gateway","disabled":false,"info":"Für diesen Flow werden 3 Informationen benötigt.\n\n - client_ID \n - client_Geheimnis\n - gerät_ID\n\nDiese Daten erhalten Sie, wenn Sie ein Account bei https://auth.tuya.com/ erstellen. Ein gutes Tutorial finden Sie überall im Netz oder hier https://www.simon42.com/homebridge-smart-life/.\n\nNachdem Sie eine Client_ID und Client_Secret haben, müssen Sie sich für folgende API-Dienste registrieren.\n\nSie sollten die folgenden API-Produkte kostenlos buchen\n\n - Verwaltung von Smart Home Geräten\n - Autorisierung\n - Smart Home Familien-Verwaltung\n - Smart Home Datendienst\n - Beta-APIs\n\nAnschließend können Sie über den API-Explorer alle Informationen zu Ihren Geräten abrufen.\nGehen Sie auf https://iot.tuya.com/cloud/explorer, wählen Sie \"Get device details\" und geben Sie Ihre device_id eines Ihrer Geräte ein.\nund geben Sie die device_id eines Ihrer Geräte ein. Wählen Sie nun das Data Center Ihrer Region aus und klicken Sie auf die Schaltfläche \"Submit Request\".\n\nAlle Daten, die Sie für diesen Ablauf benötigen, finden Sie hier.\n\nDie client_ID und die device_ID werden in den beiden Inject Nodes hinterlegt.\nDas client_Secret wird als Secret Key im hmac node hinterlegt.\n\n\n\nFor this flow, 3 pieces of information are needed.\n\n - client_ID \n - client_Secret\n - device_ID\n\nYou get this data when you create an account at https://auth.tuya.com/. A good tutorial can be found everywhere on the net or here https://www.simon42.com/homebridge-smart-life/.\n\nAfter you have a Client_ID and Client_Secret you have to register for the API service.\n\nYou should book the following API products for free \n\n - Smart Home Devices Management\n - Authorization\n - Smart Home Family Management\n - Smart Home Data Service\n - Beta APIs\n\nAfterwards you can get all information about your devices via the API Explorer.\nGo to https://iot.tuya.com/cloud/explorer select \"Get device details\" and enter your device_id of one of your LIDL devices.\nand enter your device_id of one of your LIDL devices. Now select the Data Center of your region and click on the Sumit Request button.\n\nAll data needed for this flow can be found here.\n\nclient_ID and the device_ID are stored in the two inject nodes.\nThe client_Secret is stored as secret key in hmac node."},{"id":"61063238.2d677c","type":"function","z":"d110bfa2.b69288","name":"string-to-access_token","func":"msg.payload = msg.msgSign.client_id + msg.msgSign.t;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":120,"wires":[["e93f72a.4b95e9"]]},{"id":"93f647c1.b527b","type":"inject","z":"d110bfa2.b69288","name":"An","props":[{"p":"msgSign.t","v":"","vt":"date"},{"p":"msgSign.deviceID","v":"","vt":"str"},{"p":"msgSign.client_id","v":"","vt":"str"},{"p":"msgSign.switch","v":"true","vt":"str"},{"p":"msgSign.Commands","v":"{\"commands\":\"[{\\\"code\\\":\\\"switch_1\\\",\\\"value\\\":","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":120,"wires":[["61063238.2d677c"]]},{"id":"e93f72a.4b95e9","type":"hmac","z":"d110bfa2.b69288","name":"","algorithm":"HmacSHA256","key":"","x":490,"y":120,"wires":[["9786f5cc.89211"]]},{"id":"9786f5cc.89211","type":"function","z":"d110bfa2.b69288","name":"toUpperCase","func":"msg.payload = msg.payload.toUpperCase(msg.payload)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":120,"wires":[["b6ce0969.b7ba6"]]},{"id":"b6ce0969.b7ba6","type":"change","z":"d110bfa2.b69288","name":"","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\t \"sign_method\":\"HMAC-SHA256\",\t \"client_id\":$.msgSign.client_id,\t \"t\":$.msgSign.t,\t \"sign\":$.payload\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":120,"wires":[["3b5be7ab.ee298"]]},{"id":"3b5be7ab.ee298","type":"http request","z":"d110bfa2.b69288","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://openapi.tuyaeu.com//v1.0/token?grant_type=1","tls":"","persist":false,"proxy":"","authType":"","x":1010,"y":120,"wires":[["592a3cb4.383bcc"]]},{"id":"592a3cb4.383bcc","type":"function","z":"d110bfa2.b69288","name":"Save Response","func":"flow.set(\"access_token\", msg.payload.result.access_token);\nflow.set(\"expire_time\", msg.payload.result.expire_time);\nflow.set(\"refresh_token\", msg.payload.result.refresh_token);\nflow.set(\"uid\", msg.payload.result.uid);\nflow.set(\"request_time\", msg.msgSign.t);\nflow.set(\"success\", msg.payload.success);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1200,"y":120,"wires":[["f4c13984.1be25","1133d96b.449b07"]]},{"id":"f4c13984.1be25","type":"debug","z":"d110bfa2.b69288","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1350,"y":120,"wires":[]},{"id":"36eafdd3.77bb6a","type":"function","z":"d110bfa2.b69288","name":"string-to-sign","func":"msg.payload = msg.msgSign.client_id + msg.msgSign.access_token +msg.msgSign.t;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":160,"wires":[["11a996a0.dff789"]]},{"id":"11a996a0.dff789","type":"hmac","z":"d110bfa2.b69288","name":"","algorithm":"HmacSHA256","key":"","x":590,"y":160,"wires":[["cd24038e.938168"]]},{"id":"cd24038e.938168","type":"function","z":"d110bfa2.b69288","name":"toUpperCase","func":"msg.payload = msg.payload.toUpperCase(msg.payload)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":160,"wires":[["6b54e78b.f94c18"]]},{"id":"6b54e78b.f94c18","type":"change","z":"d110bfa2.b69288","name":"","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\t \"sign_method\":\"HMAC-SHA256\",\t \"client_id\":$.msgSign.client_id,\t \"t\":$.msgSign.t,\t \"mode\":\"cors\",\t \"Content-Type\":\"application/json\",\t \"sign\":$.payload,\t \"access_token\":$.msgSign.access_token\t}","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$join([msg.msgSign.Commands,msg.msgSign.switch,'}]\"}'])\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":160,"wires":[["639a56b1.f9793"]]},{"id":"639a56b1.f9793","type":"http request","z":"d110bfa2.b69288","name":"","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://openapi.tuyaeu.com/v1.0/devices/{{{msgSign.deviceID}}}/commands","tls":"","persist":false,"proxy":"","authType":"","x":1090,"y":160,"wires":[["bc192ae7.4948e8"]]},{"id":"bc192ae7.4948e8","type":"debug","z":"d110bfa2.b69288","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1250,"y":160,"wires":[]},{"id":"1133d96b.449b07","type":"change","z":"d110bfa2.b69288","name":"","rules":[{"t":"set","p":"msgSign.access_token","pt":"msg","to":"access_token","tot":"flow"},{"t":"set","p":"msgSign.t","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":160,"wires":[["36eafdd3.77bb6a"]]},{"id":"c14d4b66.774398","type":"inject","z":"d110bfa2.b69288","name":"Aus","props":[{"p":"msgSign.t","v":"","vt":"date"},{"p":"msgSign.deviceID","v":"","vt":"str"},{"p":"msgSign.client_id","v":"","vt":"str"},{"p":"msgSign.switch","v":"false","vt":"str"},{"p":"msgSign.Commands","v":"{\"commands\":\"[{\\\"code\\\":\\\"switch_1\\\",\\\"value\\\":","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":160,"wires":[["61063238.2d677c"]]}]