# DELAY node - variable delay not seeming to work

**URL:** <https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603>\
**Category:** General\
**Created:** [21 August 2019 12:35 UTC](https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603 "2019-08-21T12:35:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 August 2019 12:35 UTC](https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603/1 "2019-08-21T12:35:50Z")

</div>

I would like to check this:

The `delay` node:  
`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.`

So with the node set to `override delay with msg.delay` I'm confused.

I send a `msg.delay` message with the value of `3000` (3 seconds)

It delays for 20 seconds.

I see the value/message going into the node and it is set.

But once the node is triggered (invoked) it goes back to the 20 seconds as set in the value.

Does the variation of the delay time have to be set at the same time as the input trigger?

Not really clear for me.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 August 2019 12:44 UTC](https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603/2 "2019-08-21T12:44:55Z")

</div>

When the delay node is configured to allow `msg.delay` to override the delay value, then each message you pass it must have its `delay` property set for how long you want _that_ message to be delayed for.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 August 2019 12:48 UTC](https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603/3 "2019-08-21T12:48:50Z")

</div>

Argh!

Ok. Can you please help me with this problem?

I need a variable delay where I can set it externally to the node.

Then when a message arrives it is delayed for that time before being sent on.

The only reason for this is so the delay can be set outside the node and varied.

Adjustments would be few and far between.

I'll dig through stuff I have been told before/earlier by others. But this is where I am at with this little project.

I know I have done variable time loops but not a delay for messages.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 August 2019 12:52 UTC](https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603/4 "2019-08-21T12:52:58Z")

</div>

Use a flow context variable to store the your desired message delay value.

Then use a Change node immediately before the Delay node to set `msg.delay` to the value of that flow context variable.

 ![Local_Node-RED](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/11677e6416558d1ff56f15a0d9017db63bde7375.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 August 2019 12:53 UTC](https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603/5 "2019-08-21T12:53:09Z")

</div>

This kind of works.

`[{"id":"7cae39a3.19f398","type":"join","z":"31b9cb24.a2ede4","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":1270,"wires":[["591c155a.73442c"]]},{"id":"d060d696.d6b6c8","type":"function","z":"31b9cb24.a2ede4","name":"","func":"msg.delay = 3500;\nmsg.payload = null;\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":1200,"wires":[["7cae39a3.19f398"]]},{"id":"8e888cf2.03616","type":"inject","z":"31b9cb24.a2ede4","name":"","topic":"","payload":"Message","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":1270,"wires":[["7cae39a3.19f398"]]},{"id":"591c155a.73442c","type":"delay","z":"31b9cb24.a2ede4","name":"Cool down time","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":680,"y":1200,"wires":[["9ee9c341.78803"]]},{"id":"e74ea714.3e2db8","type":"inject","z":"31b9cb24.a2ede4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":1200,"wires":[["d060d696.d6b6c8"]]},{"id":"9ee9c341.78803","type":"debug","z":"31b9cb24.a2ede4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":860,"y":1200,"wires":[]}]`

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 August 2019 12:59 UTC](https://discourse.nodered.org/t/delay-node-variable-delay-not-seeming-to-work/14603/6 "2019-08-21T12:59:19Z")

</div>

Thanks Nick.

Seems I am still very low on the learning curve.

But, hey: I can only go up from here I guess.
