API Tuya depuis Node-Red

Bonjour à tous,

Après avoir passé de longues heures sur le sujet et vous avoir pas mal sollicité, je peux vous livrer le fruit de ce travail.
Mon objectif était de pouvoir interroger les APIs tuya sans pour autan dupliquer les nœuds de la palette: « node-red-contrib-tuya-smart-device ». En effet c’est dernier ne permettait pas de passer les informations d’entité par le biais d’un message.
En m’inspirant du travail de notenoughtech, j’ai créé un subflow appelable facilement.
Avant de vous vous parler du subflow en particulier, je vais vous fournir une liste d’action possible.

1. Les prérequis

Pour y arriver, j’ai dû utilisé la palette suivante pour gérer le chiffrement:

node-red-contrib-crypto-js-dynamic

2. Le flow

[{"id":"4bf109a5.a97ad8","type":"tab","label":"Tuya Cloud API","disabled":false,"info":"\r\n# Tuya Cloud API for beginners\r\n\r\nThis project explains how to work with Tuya Cloud API and how to use Postman to develop REST request for NodeRED \r\nThanks to James Wilson for udating the flow to match latest authtentication requirement\r\n\r\n\r\n![Logo](https://notenoughtech.com/wp-content/uploads/2021/07/2021-07-12-23_35_30-Brand-Logo-Guidelines-Video-v2.0.0_0817.pdf-Personal-Microsoft%E2%80%8B-Edge.jpg)\r\n\r\n    \r\n## Features\r\n\r\n- Authentication\r\n- Get device list\r\n- Get status and data points\r\n- Issue commands\r\n\r\n  \r\n## Documentation\r\n\r\n[Documentation](https://linktodocumentation)\r\n\r\n  \r\n## More on\r\n\r\nVisit my page and the [article](https://notenoughtech.com/home-automation/tuya-cloud-api/) covering this topic.\r\n\r\n  \r\n## Appendix\r\n\r\nPostman, Tuya Cloud API\r\n  \r\n## 🔗 Follow my work\r\n[![Twitter Follow](https://img.shields.io/twitter/follow/notenoughtech?label=%40notenoughtech&logo=twitter&style=for-the-badge)](https://twitter.com/NotEnoughTECH)\r\n[![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UC7V__uBIaZotHn_smHJShGQ?label=NotEnoughTech&logo=YouTube&logoColor=red&style=for-the-badge)](https://www.youtube.com/channel/UC7V__uBIaZotHn_smHJShGQ)\r\n[![Subreddit subscribers](https://img.shields.io/reddit/subreddit-subscribers/not_enough_tech?logo=reddit&logoColor=white&style=for-the-badge)](https://www.reddit.com/r/Not_Enough_Tech/)","env":[]},{"id":"5313998d.974bb8","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/devices/\" + device_id +\"/status\";\nvar t = msg.time;\nvar method = \"GET\";\nvar client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar token = creds.access_token;\nvar sign = msg.payload;\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : token\n },\n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":440,"wires":[["3ac1a645.0bb26a"]]},{"id":"3ac1a645.0bb26a","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":440,"wires":[["c5c9b72789116e0f"]]},{"id":"a87ea183.b0d6b","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":440,"wires":[["d5eaa68e.d5e5c8"]]},{"id":"d5eaa68e.d5e5c8","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\n//var token = access_token;\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/devices/\" + device_id +\"/status\";\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\n\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.debug = {\n    \"access_token\": access_token,\n    \"device_id\": device_id,\n    \"t\": t,\n    \"client_id\": client_id,\n    \"method\": method,\n    \"sign_url\": sign_url,\n    \"string_to_sign\": string_to_sign,\n    \"signStr\": signStr\n}\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":440,"wires":[["f6881316.41cdb"]]},{"id":"f6881316.41cdb","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":440,"wires":[["5313998d.974bb8"]]},{"id":"f811e1b6.ee796","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var url = \"https://openapi.tuyaeu.com/v1.0/token?grant_type=1\";\nvar t = msg.time;\nvar sign = msg.payload;\nvar client_id  = flow.get(\"tuya_client_id\");\n\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"sign\": sign.toUpperCase(),\n },\n \n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":140,"wires":[["1bfa922b.aad55e"]]},{"id":"1bfa922b.aad55e","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":140,"wires":[["74db8d4a.eee2c4"]]},{"id":"3023a9a8.6133e6","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":140,"wires":[["26588c1b.dcec54"]]},{"id":"26588c1b.dcec54","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var client_id  = flow.get(\"tuya_client_id\");\nvar t = msg.time;\n\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/token?grant_type=1\";\n\n// Couldn't get nodered to process an empty string so this is a hash of an empty file\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id+t+string_to_sign;\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":140,"wires":[["5eeed491.cd055c"]]},{"id":"5eeed491.cd055c","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":140,"wires":[["f811e1b6.ee796"]]},{"id":"b1615793.fd0548","type":"comment","z":"4bf109a5.a97ad8","name":"Get Access Token","info":"","x":110,"y":100,"wires":[]},{"id":"608b6d1e.a8a874","type":"comment","z":"4bf109a5.a97ad8","name":"Get Status Of Device","info":"","x":120,"y":400,"wires":[]},{"id":"74db8d4a.eee2c4","type":"function","z":"4bf109a5.a97ad8","name":"Extract Token from Response","func":"var data = msg.payload;\nvar access = data.result.access_token;\nvar refresh = data.result.refresh_token;\n\nvar creds ={\n \"access_token\" : access,\n \"refresh_token\" : refresh\n}\nflow.set(\"tuya\", creds);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1120,"y":140,"wires":[["c98fa8a4f17d4a45"]]},{"id":"bbb94560.17a528","type":"function","z":"4bf109a5.a97ad8","name":"Settings CLICK SETUP TAB","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"var client_id = \"Votre client_id\";\nvar user_id = \"Votre user_id\";\nvar device_id = \"Votre device_id\";\nflow.set(\"tuya_client_id\", client_id);\nflow.set(\"tuya_user_id\", user_id );\nflow.set(\"device_id\", device_id );","finalize":"","libs":[],"x":340,"y":100,"wires":[[]]},{"id":"14af15b8.86c55a","type":"comment","z":"4bf109a5.a97ad8","name":"Turn Device Off","info":"","x":100,"y":900,"wires":[]},{"id":"ae0294c.e17c268","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/devices/\"+device_id+\"/commands\";\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar sign = msg.payload;\n\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : access_token,\n },\n msg.payload = '{\"commands\":[{\"code\":\"switch_1\",\"value\":false}]}';\n msg.url = url;\n msg.method = \"POST\";\n //msg.payload = '';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":960,"wires":[["448c54b6.42427c"]]},{"id":"448c54b6.42427c","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":1130,"y":960,"wires":[["7c5992c9fc2f493b"]]},{"id":"e5b52f57.cd35e","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"commands\":[{\"code\":\"switch_1\",\"value\":false}]}","payloadType":"str","x":90,"y":960,"wires":[["7bf971b.8e0989"]]},{"id":"7f3ecdbc.908f24","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id = flow.get(\"tuya_client_id\");\n\nvar method = \"POST\";\nvar sign_url = \"/v1.0/devices/\" + device_id + \"/commands\";\nvar content_hash = msg.payload;\n\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":960,"wires":[["17bac91b.4b1287"]]},{"id":"17bac91b.4b1287","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":790,"y":960,"wires":[["ae0294c.e17c268"]]},{"id":"9295d1f4.912c5","type":"comment","z":"4bf109a5.a97ad8","name":"Turn Device On","info":"","x":100,"y":1020,"wires":[]},{"id":"c2dcb090.24f8f","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/devices/\"+device_id+\"/commands\";\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar sign = msg.payload;\n\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : access_token,\n },\n msg.payload = '{\"commands\":[{\"code\":\"switch_1\",\"value\":true}]}';\n msg.url = url;\n msg.method = \"POST\";\n //msg.payload = '';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":1080,"wires":[["f6260f4c.e8663"]]},{"id":"f6260f4c.e8663","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":1030,"y":1080,"wires":[["377d9f7f4417f343"]]},{"id":"556e864.5344d78","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"commands\":[{\"code\":\"switch_1\",\"value\":true}]}","payloadType":"str","x":90,"y":1080,"wires":[["a21182b6.3a489"]]},{"id":"c4e6dff.719862","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id = flow.get(\"tuya_client_id\");\n\nvar method = \"POST\";\nvar sign_url = \"/v1.0/devices/\"+device_id+\"/commands\";\nvar content_hash = msg.payload;\n\nvar string_to_sign = method + \"\\n\" + content_hash + \"\\n\" + \"\" + \"\\n\" + sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":1080,"wires":[["552476b9.24cad8"]]},{"id":"552476b9.24cad8","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":690,"y":1080,"wires":[["c2dcb090.24f8f"]]},{"id":"a21182b6.3a489","type":"digest","z":"4bf109a5.a97ad8","name":"Hash the body data","algorithm":"SHA256","x":250,"y":1080,"wires":[["c4e6dff.719862"]]},{"id":"7bf971b.8e0989","type":"digest","z":"4bf109a5.a97ad8","name":"Hash the body data","algorithm":"SHA256","x":310,"y":960,"wires":[["7f3ecdbc.908f24"]]},{"id":"c5c9b72789116e0f","type":"debug","z":"4bf109a5.a97ad8","name":"debug 114","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":440,"wires":[]},{"id":"c98fa8a4f17d4a45","type":"debug","z":"4bf109a5.a97ad8","name":"debug 115","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1370,"y":140,"wires":[]},{"id":"377d9f7f4417f343","type":"debug","z":"4bf109a5.a97ad8","name":"debug 117","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1230,"y":1080,"wires":[]},{"id":"7c5992c9fc2f493b","type":"debug","z":"4bf109a5.a97ad8","name":"debug 118","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1330,"y":960,"wires":[]},{"id":"23e99629deccef57","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/devices/\" + device_id;\nvar t = msg.time;\nvar method = \"GET\";\nvar client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar token = creds.access_token;\nvar sign = msg.payload;\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : token\n },\n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":540,"wires":[["5e546a662abf2f04"]]},{"id":"5e546a662abf2f04","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":540,"wires":[["a4850647bd54dc0f"]]},{"id":"93c23bf263dd9476","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":540,"wires":[["e043d4855d18f0ab"]]},{"id":"e043d4855d18f0ab","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\n//var token = access_token;\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/devices/\" + device_id;\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\n\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.debug = {\n    \"access_token\": access_token,\n    \"device_id\": device_id,\n    \"t\": t,\n    \"client_id\": client_id,\n    \"method\": method,\n    \"sign_url\": sign_url,\n    \"string_to_sign\": string_to_sign,\n    \"signStr\": signStr\n}\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":540,"wires":[["1ad96ee78fd5323c"]]},{"id":"1ad96ee78fd5323c","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":540,"wires":[["23e99629deccef57"]]},{"id":"b2fa088976f10c85","type":"comment","z":"4bf109a5.a97ad8","name":"Get Device Information","info":"","x":120,"y":500,"wires":[]},{"id":"a4850647bd54dc0f","type":"debug","z":"4bf109a5.a97ad8","name":"debug 119","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":540,"wires":[]},{"id":"f8d92f0bcbbe2951","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/functions/dj\";\nvar t = msg.time;\nvar method = \"GET\";\nvar client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar token = creds.access_token;\nvar sign = msg.payload;\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : token\n },\n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":640,"wires":[["e75bc80a537bf083"]]},{"id":"e75bc80a537bf083","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":640,"wires":[["207ef8534396b733"]]},{"id":"5e5adc8f77f4a84d","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":640,"wires":[["9890980b77d323a0"]]},{"id":"9890980b77d323a0","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\n//var token = access_token;\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/functions/dj\";\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\n\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.debug = {\n    \"access_token\": access_token,\n    \"device_id\": device_id,\n    \"t\": t,\n    \"client_id\": client_id,\n    \"method\": method,\n    \"sign_url\": sign_url,\n    \"string_to_sign\": string_to_sign,\n    \"signStr\": signStr\n}\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":640,"wires":[["f78bf512cde6a8d0"]]},{"id":"f78bf512cde6a8d0","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":640,"wires":[["f8d92f0bcbbe2951"]]},{"id":"b39c69e035eb7213","type":"comment","z":"4bf109a5.a97ad8","name":"Get Function List","info":"","x":100,"y":600,"wires":[]},{"id":"207ef8534396b733","type":"debug","z":"4bf109a5.a97ad8","name":"debug 120","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":640,"wires":[]},{"id":"0c0459698d8bb296","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/devices/\" + device_id +\"/status\";\nvar t = msg.time;\nvar method = \"GET\";\nvar client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar token = creds.access_token;\nvar sign = msg.payload;\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : token\n },\n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":740,"wires":[["f670e7bcad81de3c"]]},{"id":"f670e7bcad81de3c","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":740,"wires":[["12c54aa25fe558fa"]]},{"id":"b4430cf3e3591e56","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":740,"wires":[["87c02ade58431cd2"]]},{"id":"87c02ade58431cd2","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\n//var token = access_token;\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/devices/\" + device_id + \"/status\";\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\n\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.debug = {\n    \"access_token\": access_token,\n    \"device_id\": device_id,\n    \"t\": t,\n    \"client_id\": client_id,\n    \"method\": method,\n    \"sign_url\": sign_url,\n    \"string_to_sign\": string_to_sign,\n    \"signStr\": signStr\n}\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":740,"wires":[["0040e12abf3b9894"]]},{"id":"0040e12abf3b9894","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":740,"wires":[["0c0459698d8bb296"]]},{"id":"95f65d994f5acc43","type":"comment","z":"4bf109a5.a97ad8","name":"Get device Data Points","info":"","x":120,"y":700,"wires":[]},{"id":"12c54aa25fe558fa","type":"debug","z":"4bf109a5.a97ad8","name":"debug 121","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":740,"wires":[]},{"id":"e66de0857f95a9a8","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/devices/\" + device_id +\"/functions\";\nvar t = msg.time;\nvar method = \"GET\";\nvar client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar token = creds.access_token;\nvar sign = msg.payload;\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : token\n },\n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":840,"wires":[["75a8cd4bfd3a6fdd"]]},{"id":"75a8cd4bfd3a6fdd","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":840,"wires":[["5ec348212f88adf5"]]},{"id":"ab7ee184a2fe44fa","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":840,"wires":[["0e6e99d81893b1c3"]]},{"id":"0e6e99d81893b1c3","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\n//var token = access_token;\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/devices/\" + device_id + \"/functions\";\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\n\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.debug = {\n    \"access_token\": access_token,\n    \"device_id\": device_id,\n    \"t\": t,\n    \"client_id\": client_id,\n    \"method\": method,\n    \"sign_url\": sign_url,\n    \"string_to_sign\": string_to_sign,\n    \"signStr\": signStr\n}\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":840,"wires":[["13c60cf5b1d73ab9"]]},{"id":"13c60cf5b1d73ab9","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":840,"wires":[["e66de0857f95a9a8"]]},{"id":"74b0ef9695dfbc2d","type":"comment","z":"4bf109a5.a97ad8","name":"Query instruction sets supported by the device","info":"","x":190,"y":800,"wires":[]},{"id":"5ec348212f88adf5","type":"debug","z":"4bf109a5.a97ad8","name":"debug 122","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":840,"wires":[]},{"id":"3a4846e01f72bc11","type":"comment","z":"4bf109a5.a97ad8","name":"Sources","info":"This flow is the result of a sharing by notenoughtech.\nHere are his web pages:\n\nhttps://github.com/notenoughtech/NodeRED-Projects/tree/master/Tuya%20Cloud%20API\nhttps://notenoughtech.com/home-automation/tuya-cloud-api/\n\nThe use of this flow requires the use of the palette:\nnode-red-contrib-crypto-js-dynamic\n","x":80,"y":40,"wires":[]},{"id":"df0d278f20fc21f6","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var creds = flow.get(\"tuya\");\nvar refresh_token = creds.refresh_token;\nvar t = msg.time;\n\n\nvar url = \"https://openapi.tuyaeu.com/v1.0/token/\" + refresh_token;\nvar sign = msg.payload;\nvar client_id  = flow.get(\"tuya_client_id\");\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"sign\": sign.toUpperCase(),\n },\n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":240,"wires":[["8b69823e8ad4030a"]]},{"id":"8b69823e8ad4030a","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":240,"wires":[["83baa287f862c021"]]},{"id":"2a73ddecefdf44a9","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":240,"wires":[["7cf80c54805c3142"]]},{"id":"7cf80c54805c3142","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var client_id  = flow.get(\"tuya_client_id\");\nvar creds = flow.get(\"tuya\");\nvar refresh_token = creds.refresh_token;\nvar t = msg.time;\n\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/token/\" + refresh_token;\n\n// Couldn't get nodered to process an empty string so this is a hash of an empty file\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id+t+string_to_sign;\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":240,"wires":[["e44d5c4aec4df707"]]},{"id":"e44d5c4aec4df707","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":240,"wires":[["df0d278f20fc21f6"]]},{"id":"04842d2df13a643b","type":"comment","z":"4bf109a5.a97ad8","name":"Refresh Token","info":"","x":90,"y":200,"wires":[]},{"id":"83baa287f862c021","type":"function","z":"4bf109a5.a97ad8","name":"Extract Token from Response","func":"var data = msg.payload;\nvar access = data.result.access_token;\nvar refresh = data.result.refresh_token;\n\nvar creds ={\n \"access_token\" : access,\n \"refresh_token\" : refresh\n}\nflow.set(\"tuya\", creds);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1120,"y":240,"wires":[["33c389baa65a4fe7"]]},{"id":"33c389baa65a4fe7","type":"debug","z":"4bf109a5.a97ad8","name":"debug 123","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1370,"y":240,"wires":[]},{"id":"02c15c74b19ad952","type":"comment","z":"4bf109a5.a97ad8","name":"Get a list of devices under a specified user","info":"","x":180,"y":300,"wires":[]},{"id":"bfc4359fff1d339a","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var device_id = flow.get(\"device_id\");\nvar client_id = flow.get(\"tuya_client_id\");\nvar tuya_user_id = flow.get(\"tuya_user_id\");\nvar url = \"https://openapi.tuyaeu.com/v1.0/users/\" + tuya_user_id + \"/devices\";\nvar t = msg.time;\nvar method = \"GET\";\nvar creds = flow.get(\"tuya\");\nvar token = creds.access_token;\nvar sign = msg.payload;\n\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"mode\" : \"cors\",\n \"Content-Type\": \"application/json\",\n \"sign\": sign.toUpperCase(),\n \"access_token\" : token\n },\n \n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":340,"wires":[["106527b0a025f5e4"]]},{"id":"106527b0a025f5e4","type":"http request","z":"4bf109a5.a97ad8","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":340,"wires":[["d6d85945c72762ce"]]},{"id":"26ad12a9223761f0","type":"inject","z":"4bf109a5.a97ad8","name":"","props":[{"p":"time","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":340,"wires":[["c969c83d52502b9a"]]},{"id":"c969c83d52502b9a","type":"function","z":"4bf109a5.a97ad8","name":"Create signStr","func":"var creds = flow.get(\"tuya\");\nvar access_token = creds.access_token;\nvar device_id = flow.get(\"device_id\");\nvar t = msg.time;\nvar client_id  = flow.get(\"tuya_client_id\");\nvar tuya_user_id = flow.get(\"tuya_user_id\");\n//var token = access_token;\n\nvar method = \"GET\";\nvar sign_url = \"/v1.0/users/\" + tuya_user_id + \"/devices\";\nvar content_hash = \"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\";\n\nvar string_to_sign = method+\"\\n\"+content_hash+\"\\n\"+\"\"+\"\\n\"+sign_url;\nvar signStr = client_id + access_token + t + string_to_sign;\n\nmsg.payload = signStr;\nmsg.time = msg.time;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":340,"wires":[["90b50f4cb19d6b6f"]]},{"id":"90b50f4cb19d6b6f","type":"hmac","z":"4bf109a5.a97ad8","name":"Sign signStr with secret","algorithm":"HmacSHA256","key":"58fb24515a07454886120147b4225450","x":490,"y":340,"wires":[["bfc4359fff1d339a"]]},{"id":"d6d85945c72762ce","type":"debug","z":"4bf109a5.a97ad8","name":"debug 135","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":340,"wires":[]}]

Pas d’inquiétude, j’ai tenté de vous référencer une liste non exhaustive des possibilités.

  1. Settings CLICK SETUP TAB
    Cette fonction set à charger vos valeurs de connexion aux API lors du lancement.
    Aller dans l’onglet On Start
var client_id = "votre Client_ID";
var user_id = "Le user";
var device_id = "ID du périphérique";
flow.set("tuya_client_id", client_id);
flow.set("tuya_user_id", user_id );
flow.set("device_id", device_id );

Ces informations sont récupérables comme suit:
Sur le site iot.tuya.com

         1. client_id

Se rendre sur
image

Ouvrir votre projet pour home assistant
Dans l’onglet Overview le client ID:

image

         2. user_id

image

         3. device_id

image

PS: Une info qui peut avoir son improtance le nombre de requête: ICI

Avec 500 000 /jour on est large

1 « J'aime »

Merci pour le partage

Bonjour et merci pour le flow.
Est ce qu’il faut des noeuds particuliers à part le « node-red-contrib-crypto-js-dynamic » ?
J’ai bien rentré les données demandées sur le noeud « Settings CLICK SETUP TAB » =>
Credentials
, et à chaque injection, j’obtiens ça =>
Access token

Merci :wink:

Je viens de retester chez moi et cela fonctionne.

Arrives-tu a obtenir un token valide?
Voici ce que je récupère chez moi.

{"_msgid":"2f8d42dcf15fd0ae","time":1696342962251,"topic":"","payload":{"result":{"access_token":"c997b28axxx7668e87b4c294d1837","expire_time":3627,"refresh_token":"1cf91d9ca9exxxxacb442f6b07c2a4","uid":"bay1659877744482gQzn"},"success":true,"t":1696342962396,"tid":"xxxxx"},"headers":{"content-type":"application/json;charset=UTF-8","content-length":"235","connection":"close","date":"Tue, 03 Oct 2023 14:22:42 GMT","access-control-allow-credentials":"true","access-control-allow-headers":", access_token,Content-Type","access-control-allow-methods":"POST, OPTIONS, GET, DELETE, PUT","access-control-allow-origin":"https://iot.tuya.com","gateway-info":"highway","server":"Sec","strict-transport-security":"max-age=31536000","x-node-red-request-node":"468789bd"},"url":"https://openapi.tuyaeu.com/v1.0/token?grant_type=1","method":"GET","statusCode":200,"responseUrl":"https://openapi.tuyaeu.com/v1.0/token?grant_type=1","redirectList":[],"retry":0}

Tu devrais trouver une variable de flow avec les valeurs appelée tuya.

Hello, voilà ce que j’obtiens :

Apparemment pas de token après le http request.

Salut

Tu pourrais envoyer le JSON de sortie 177 pour que qu’on y voit plus clair STP?

Par ailleurs, dit moi ce que t’as dans ton onglet « Context Data ».

Salut, voilà le context

et le json :</> [{"id":"f811e1b6.ee796","type":"function","z":"4bf109a5.a97ad8","name":"","func":"var url = \"https://openapi.tuyaeu.com/v1.0/token?grant_type=1\";\nvar t = msg.time;\nvar sign = msg.payload;\nvar client_id = flow.get(\"tuya_client_id\");\n\nmsg.headers ={\n \"sign_method\": \"HMAC-SHA256\",\n \"client_id\" : client_id,\n \"t\": t.toString(),\n \"sign\": sign.toUpperCase(),\n },\n \n msg.payload = '';\n msg.url = url;\n msg.method = \"GET\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":140,"wires":[["1bfa922b.aad55e","399058ccffd59301"]]}] </>

Bonjour,

Tout d’abord quand tu envoies du code, pense à utiliser:
image
c’est plus simple à lire.

Je ne comprends pas ce qui ce passe. On dirai que la fonction n’est pas interprétée.
Ton debug 177, il te renvoie le message complet?
Il ne ressemble en rien à ce qui sort de la fonction chez moi.

{
"_msgid":"da882eb6a97d374b",
"time":1696470271375,
"topic":"",
"payload":"",
"headers":{
  "sign_method":"HMAC-SHA256",
  "client_id":"gs4wa87kd477esxcjunu",
  "t":"1696470271375",
  "sign":"EB6ECFA51D3563CBB21BA388B62564DA84B0F9EA25E26A1492792D130AB78C52"
  },
"url":"https://openapi.tuyaeu.com/v1.0/token?grant_type=1",
"method":"GET"
}

As-tu bien installé la palette: node-red-contrib-crypto-js-dynamic?
As-tu touché au code embarqué dans les fonctions?

J’y pense maintenant (sans y croire), j’ai activé la persistance des données node-red:
Est-ce que tu as décommenté ou ajouté ces lignes dans ton fichier mode-red/settings.js:

  contextStorage: {
    default: {
        module: "localfilesystem"
    },
    memoryOnly: {
        module: "memory"
    }
  },

Enfin quelle version de node-red utilises-tu? J’ai eu des souci avec la dernière sur laquelle, j’ai fait un roll back

On va finir par trouver renvoies le debug 175 et 176 que je vois quel tête ils ont.

Rehello, merci pour la réponse, oui on va y arriver.

Dans l’ordre :

  1. La palette est bien installée
    Crypto

  2. Pas de retouche dans le code

  3. Le setting.js
    Config

  4. Version Node-Red : 14.4.5, j’étais aussi revenu à l’ancienne version suite aux messages d’erreurs
    Version nodered

  5. le debug 175 (Create signStr)

{"_msgid":"aabbc3b485eae7bd",
"time":1696487506962,
"topic":"",
"payload":"ncenrr9xhmhhxpxq3xnp1696487506962GET\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n\n/v1.0/token?grant_type=1"}
  1. Le debug 176 (Sign signStr with secret)
{"_msgid":"aabbc3b485eae7bd",
"time":1696487506962,
"topic":"",
"payload":"4aead8c2364754ea1ded0f14af16b9eb13d015db4df559aef0eba6410e4b3e1e"}

Merci.

chez moi j’ai à la sortie de la première fonction

{
"_msgid":"3b498c0ed5174fb5",
"time":1696527681551,
"topic":"",
"payload":"gs4wa87kd477esxcjunu1696527681551GET\ne3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n\n/v1.0/token?grant_type=1"}

Le seconde

{
"_msgid":"47ddc473adc2972b",
"time":1696528358156,
"topic":"",
"payload":"a2d7fa4b0668de07364fc98fd22955ab69fe0d5879f59c1a568c8aaa2e015d06"}

Donc le souci n’est pas le code. Tes sorties semblent être les mêmes. J’y pense est que tu as donné les droits d’accès à tes APIs sur tuya ioa
Perso j’ai ça sur mon appli:

Au passage contrôle les valeurs user_id et client_id.

Hello,
Bon finalement j’obtiens la réponse suivante au noeud 115 :

object
_msgid: "f8892de6ad36XXXX"
time: 1696589691210
topic: ""
payload: object
result: object
access_token: "6a5bbf08fd4131500XXXXXXX"
expire_time: 6954
refresh_token: "689ee1c68f8d052XXXXXX"
uid: "bay1664357415035XXXX"
success: true
t: 1696589691307
tid: "c64d1325643XXXXXXXX"
headers: object
content-type: "application/json;charset=UTF-8"
content-length: "235"
connection: "close"
date: "Fri, 06 Oct 2023 10:54:51 GMT"
access-control-allow-credentials: "true"
access-control-allow-headers: ", access_token,Content-Type"
access-control-allow-methods: "POST, OPTIONS, GET, DELETE, PUT"
access-control-allow-origin: "https://iot.tuya.com"
gateway-info: "highway"
server: "Sec"
strict-transport-security: "max-age=31536000"
x-node-red-request-node: "2b1f0601"
url: "https://openapi.tuyaeu.com/v1.0/token?grant_type=1"
method: "GET"
statusCode: 200
responseUrl: "https://openapi.tuyaeu.com/v1.0/token?grant_type=1"
redirectList: array[0]
retry: 0

Ça parait correct par rapport à ton résultat du dessus.
A un moment je me suis posé la question, « mais elle sort d’où la clé secrête ? » , du coup j’ai mis la mienne, et ça va beaucoup mieux. Comme tu disais de ne pas toucher au code, à part pour « Settings CLICK SETUP TAB », je n’avais pas cherché dedans.
code

Merci :wink:

Bonjour,

Je cherchais justement un code comme celui ci ! Merci a toi d’avoir pris le temps de partager.
J’ai également une erreur du type :

14/10/2023 10:53:26[noeud: Extract Token from Response]
« TypeError: Cannot read properties of undefined (reading ‹ access_token ›) »

J’ai pourtant ajouter modifier les 3 paramètres demandés dans Settings CLICK SETUP TAB :

var client_id = « wjkask3XXXXXXXXXXX »;
var user_id = « eu153XXXXXXXXXXXXX »;
var device_id = « bf8a0XXXXXXXXXXXX »;

et ajouter ma clé secret dans le noeud « Sign signStr with secret »

Ai-je manqué quelque chose d’autre ?

Merci à vous !

J’ai trouvé mon erreur !
C’était dans le nœud « Settings CLICK SETUP TAB » quand on ouvre on entre nos paramètres sur le sous onglet « message reçu » alors qu’il faut évidement le mettre dans l’onglet « au démarrage » car le nœud n’est pas relié. Erreur bête. Si ca peut servir a quelqu’un.

Super en tout cas ca marche nickel merci alexb81

Bonjour,

Désolé de ne pas avoir vu ton message. Content que tu ai trouvé. Je viens d’apporter une modification sur la gestion de mes volets publiée sur un autre post. Quand j’aurais le temps de le mettre à jour, j’en profiterai pour améliorer celui-ci.

Bonne journée

Désolé, de deterrer le sujet, mais je me dois de remercier l’auteur. Apres avoir galerer avec tuya_local de make-all, pour ouvrir mon lock de tiroir, chercher comment intégré une clé tuya, puis tuya_ble. Rien ne fonctionnait.
J’ai commencer a regarder tuya2mqtt, puis node red et suis tomber par hazard apres de nombreuse video incomprenhensible pour moi sur ce topic.
Il m’a fallu 10 min pour reussir a ouvrir mon tiroir, je suis tellement content que je me devais de poster ce remerciement.
J’ai meme reussi a ajouter un bouton pour lié home assistant et node red facilement (bon j’arrive pas encore a faire en sorte que mon bouton declenche l’inject de recuperation du token, puis l’inject d’ouverture du tiroir, mais actuellement, en déclenchant l’inject d’ouverture du tiroir, ca fonctionne) donc je suis heureux :heart_eyes:
Grand merci @alexb81
Je vais meme voir si je peux faire pareil avec mes serrures connectées.