can i use variables for ip, device and key? node-red-contrib-tuya-local

Hello, I am starting with node red, I want to use the same process to see the status of different smart life devices.
I am using node-red-contrib-tuya-local, if I put the fixed values, but I don't know how to introduce variables

I have a previous function with a switch, which returns a msg.ip, msg.id and msg.key
then I pass them to flow variables, but I don't know how to use the value of the msg or the flow variable
I don't know how is the syntax to put a variable

Hi, i don't know if the fields of the nodes from fields node-red-contrib-tuya-local supports mustache notation but i would give a try. You can set msg properties via change node to set message properties and use mustache notation to set them in fields.

In this example msg.searchurl is set to Google and msg.phrase to nodeRed. With the next http request node we set the URL field to {{{searchurl}}}{{phrase}} and perform a request. Now url field will be dynamically filled with nodeRed - Google Search. {{{}}} doesn't encode special chars, standard mustache is {{propertyname}}. Accessing msg.payload property is done by {{payload.property}}.

[{"id":"ce062ee07be7383f","type":"tab","label":"NodeRED Forum","disabled":false,"info":"","env":[]},{"id":"efab57613435f404","type":"inject","z":"ce062ee07be7383f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":280,"wires":[["41ace6d2ae00aa33"]]},{"id":"41ace6d2ae00aa33","type":"change","z":"ce062ee07be7383f","name":"","rules":[{"t":"set","p":"searchurl","pt":"msg","to":"https://www.google.com/search?q=","tot":"str"},{"t":"set","p":"phrase","pt":"msg","to":"nodeRED","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":280,"wires":[["db6afe42e39a8b86"]]},{"id":"db6afe42e39a8b86","type":"http request","z":"ce062ee07be7383f","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"{{{searchurl}}}{{phrase}}","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[],"x":510,"y":280,"wires":[["63957e0c969389d1"]]},{"id":"63957e0c969389d1","type":"debug","z":"ce062ee07be7383f","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":280,"wires":[]}]

Hope this helps,

Cheers

hello,
Thanks for your time, it doesn't work, I tried and it doesn't work, this is the example

[{"id":"170f763669e59c78","type":"tab","label":"Flow 6","disabled":false,"info":"","env":[]},{"id":"ce94ddbe74a3612b","type":"debug","z":"170f763669e59c78","name":"caja 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":950,"y":220,"wires":[]},{"id":"17809aab709ea232","type":"inject","z":"170f763669e59c78","name":"pruebas","props":[{"p":"dispositivo","v":"Pruebas","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"request","payloadType":"str","x":220,"y":400,"wires":[["bb371a540b3bdd49"]]},{"id":"bb371a540b3bdd49","type":"function","z":"170f763669e59c78","name":"","func":"switch (msg.dispositivo) {\n  case \"Pruebas\":\n    msg.ip      =\"192.168.1.75\";\n    msg.id      =\"cf07864fc94ce0151cznnq\";\n    msg.key     =\"260fb4437b59d1e5\";\n    break;\n  case \"Depuradora\":\n    msg.ip      =\"192.168.1.76\";\n    msg.id      =\"cf07864fc94ce0151cznnq\";\n    msg.key     =\"260fb4437b59d1e5\";\n    break;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":240,"wires":[["3eeab318c8edb926"]]},{"id":"3eeab318c8edb926","type":"tuya-local","z":"170f763669e59c78","devName":"Pruebas","devIp":"{{{ip}}}","devId":"{{{id}}}","devKey":"{{{key}}}","protocolVer":"3.3","renameSchema":"","filterCB":"","x":660,"y":320,"wires":[["ce94ddbe74a3612b"]]}]

Hi, than you have to switch the "dispositivo" property and use two tuya nodes configured separately:

[{"id":"170f763669e59c78","type":"tab","label":"Flow 6","disabled":false,"info":"","env":[]},{"id":"17809aab709ea232","type":"inject","z":"170f763669e59c78","name":"pruebas","props":[{"p":"dispositivo","v":"Pruebas","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"request","payloadType":"str","x":400,"y":600,"wires":[["f62ff4a3ceb04821"]]},{"id":"f62ff4a3ceb04821","type":"switch","z":"170f763669e59c78","name":"","property":"dispositivo","propertyType":"msg","rules":[{"t":"eq","v":"Pruebas","vt":"str"},{"t":"eq","v":"Depuradora","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":600,"wires":[["3eeab318c8edb926"],["dc7e48de94752fc4"]]},{"id":"3eeab318c8edb926","type":"tuya-local","z":"170f763669e59c78","devName":"Pruebas","devIp":"192.168.1.75","devId":"cf07864fc94ce0151cznnq","devKey":"260fb4437b59d1e5","protocolVer":"3.3","renameSchema":"","filterCB":"","x":680,"y":580,"wires":[["5324b88e0df43789"]]},{"id":"dc7e48de94752fc4","type":"tuya-local","z":"170f763669e59c78","devName":"Pruebas","devIp":"{{{ip}}}","devId":"{{{id}}}","devKey":"{{{key}}}","protocolVer":"3.3","renameSchema":"","filterCB":"","x":680,"y":620,"wires":[["42630f0d1a41131b"]]},{"id":"5324b88e0df43789","type":"debug","z":"170f763669e59c78","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":580,"wires":[]},{"id":"42630f0d1a41131b","type":"debug","z":"170f763669e59c78","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":620,"wires":[]}]

Cheers

Thanks for your answer, that's just what I don't want to do, I don't want to have to touch anything if I add some more device, the switch is for a test, what I want is that the status check is in a subflow that I can call from any flow
(excuse my English, I use google translator)

Hi, I'm afraid I'll have to disappoint you, as the skills or deficiencies of the nodes probably only allow this path. If you feel confident, you could fork the node and adapt it to your requirements. Unfortunately, I don't see any other solution. Greetings

Is there problem (other than extra nodes in the flow) with having one node per device?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.