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

**URL:** <https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438>\
**Category:** General\
**Tags:** function-node\
**Created:** [21 July 2022 17:17 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438 "2022-07-21T17:17:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kernel](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@kernel](https://discourse.nodered.org/u/kernel)\
**Post date:** [21 July 2022 17:17 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/1 "2022-07-21T17:17:05Z")

</div>

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

 ![imagen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/6616223d0dba5d546814ba314a95eb0dd12d20a3.png)

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

 ![imagen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad12797ce6977959a78b4d4a74034661c128a082.png)

---

<div class="post-metadata">

**Author:** ![3dimensional](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/3dimensional/32/64992_2.png) [@3dimensional](https://discourse.nodered.org/u/3dimensional)\
**Post date:** [21 July 2022 18:08 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/2 "2022-07-21T18:08:12Z")

</div>

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](https://www.google.com/search?q=) 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](https://www.google.com/search?q=nodeRed). {{{}}} doesn't encode special chars, standard mustache is {{propertyname}}. Accessing msg.payload property is done by {{payload.property}}.

```auto
[{"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

---

<div class="post-metadata">

**Author:** ![kernel](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@kernel](https://discourse.nodered.org/u/kernel)\
**Post date:** [22 July 2022 07:40 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/3 "2022-07-22T07:40:21Z")

</div>

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

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![3dimensional](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/3dimensional/32/64992_2.png) [@3dimensional](https://discourse.nodered.org/u/3dimensional)\
**Post date:** [22 July 2022 10:44 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/4 "2022-07-22T10:44:39Z")

</div>

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

```auto
[{"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

---

<div class="post-metadata">

**Author:** ![kernel](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@kernel](https://discourse.nodered.org/u/kernel)\
**Post date:** [22 July 2022 11:42 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/5 "2022-07-22T11:42:56Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![3dimensional](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/3dimensional/32/64992_2.png) [@3dimensional](https://discourse.nodered.org/u/3dimensional)\
**Post date:** [22 July 2022 12:58 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/6 "2022-07-22T12:58:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 July 2022 13:12 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/7 "2022-07-22T13:12:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 September 2022 13:12 UTC](https://discourse.nodered.org/t/can-i-use-variables-for-ip-device-and-key-node-red-contrib-tuya-local/65438/8 "2022-09-20T13:12:43Z")

</div>

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