# Can I use a variable?

**URL:** <https://discourse.nodered.org/t/can-i-use-a-variable/87330>\
**Category:** General\
**Created:** [19 April 2024 08:05 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330 "2024-04-19T08:05:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![acestu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acestu/32/90408_2.png) [@acestu](https://discourse.nodered.org/u/acestu)\
**Post date:** [19 April 2024 08:05 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/1 "2024-04-19T08:05:05Z")

</div>

Hi,  
I now have 20 gauges each with a trigger that sends a 0 to the gauges if I have no mqtt coming in within a certain time, now from time to time I need to change the time on the triggers to help with troubleshooting etc, my question is can a variable be used in the trigger node as changing the time in 20 nodes is so time consuming

Thanks  
Stuart

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [19 April 2024 08:54 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/2 "2024-04-19T08:54:40Z")

</div>

Click the trigger node once and select the help panel:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66d8488b9e9f2905dfbfce301b07b788aee6b9c5.png)

It will describe what the node accepts as input: `msg.delay`

> delay number

> Sets the delay, in milliseconds, to be applied to the message. This option only applies if the node is configured to allow the message to override the configured default delay interval.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 April 2024 09:16 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/3 "2024-04-19T09:16:31Z")

</div>

You can use one trigger node if you set it to each msg.topic, you then use a switch node to direct to correct gauge.  
You can also feed in different delays for each topic if you wish.  
e.g.

```auto
[{"id":"46e9ca6abf0bc688","type":"inject","z":"d1395164b4eec73e","name":"mqtt in topic1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic1","payload":"1","payloadType":"num","x":670,"y":7600,"wires":[["7916fa6baec05626","397818ab07c739a7"]]},{"id":"7916fa6baec05626","type":"debug","z":"d1395164b4eec73e","name":"gauge 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":7600,"wires":[]},{"id":"397818ab07c739a7","type":"trigger","z":"d1395164b4eec73e","name":"","op1":"","op2":"0","op1type":"nul","op2type":"num","duration":"5","extend":true,"overrideDelay":true,"units":"s","reset":"","bytopic":"topic","topic":"topic","outputs":1,"x":740,"y":7520,"wires":[["2edb09d7971cfe2e"]]},{"id":"2edb09d7971cfe2e","type":"switch","z":"d1395164b4eec73e","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"topic1","vt":"str"},{"t":"eq","v":"topic2","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":7520,"wires":[["7916fa6baec05626"],["200e33fad41b9463"]]},{"id":"3312c19a6f0d2b35","type":"inject","z":"d1395164b4eec73e","name":"mqtt in topic 2","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"delay","v":"10000","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"topic2","payload":"2","payloadType":"num","x":670,"y":7660,"wires":[["200e33fad41b9463","397818ab07c739a7"]]},{"id":"200e33fad41b9463","type":"debug","z":"d1395164b4eec73e","name":"gauge 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":7660,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![acestu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acestu/32/90408_2.png) [@acestu](https://discourse.nodered.org/u/acestu)\
**Post date:** [19 April 2024 09:18 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/4 "2024-04-19T09:18:00Z")

</div>

Hi bakman2,

Thanks for the info

Stuart

---

<div class="post-metadata">

**Author:** ![acestu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acestu/32/90408_2.png) [@acestu](https://discourse.nodered.org/u/acestu)\
**Post date:** [19 April 2024 09:32 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/5 "2024-04-19T09:32:23Z")

</div>

Hi E1cid again,

I had a look at the trigger and I don't think it allows a variable for the time as there is no dropdown box offering variables, I will have a look at your method and see if i can work something out

Thanks  
Stuart

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 April 2024 09:36 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/6 "2024-04-19T09:36:12Z")

</div>

The variable is in the inject node msg.delay, topic 2 is set to 10 seconds. Topic one has no delay property so will use the 5 seconds set in the trigger node.

---

<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:** [19 April 2024 10:18 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/7 "2024-04-19T10:18:47Z")

</div>

Or you could use an environment variable, which you can set in settings.js, or outside the node-red environment.

---

<div class="post-metadata">

**Author:** ![acestu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acestu/32/90408_2.png) [@acestu](https://discourse.nodered.org/u/acestu)\
**Post date:** [19 April 2024 14:44 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/8 "2024-04-19T14:44:41Z")

</div>

Thanks for the explanation E1cid, I love learning how different things work in Node-Red

Stuart

---

<div class="post-metadata">

**Author:** ![acestu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acestu/32/90408_2.png) [@acestu](https://discourse.nodered.org/u/acestu)\
**Post date:** [19 April 2024 14:46 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/9 "2024-04-19T14:46:28Z")

</div>

Hi Colin,  
Thanks for your info too, I thought of variables because I have used them in the past when tinkering with Basic  
Thanks  
Stuart

---

<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:** [18 July 2024 14:46 UTC](https://discourse.nodered.org/t/can-i-use-a-variable/87330/10 "2024-07-18T14:46:49Z")

</div>

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