# Delay time node red

**URL:** <https://discourse.nodered.org/t/delay-time-node-red/88159>\
**Category:** General\
**Tags:** function-node\
**Created:** [22 May 2024 09:00 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159 "2024-05-22T09:00:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [22 May 2024 09:00 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/1 "2024-05-22T09:00:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8ee32237cc2a2d2e9963f092ca2fe616283b5cad.png)  
Help me make a delay function node red for this picture.  
Tks.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 May 2024 09:08 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/2 "2024-05-22T09:08:51Z")

</div>

Please explain (in words) what you need. That picture of text is very ambiguous and unclear.

PS, there are switch nodes to check value and delay nodes for delaying, so it is unclear why you have tagged #function-node

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [22 May 2024 09:32 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/3 "2024-05-22T09:32:05Z")

</div>

[flows (1).json](https://discourse.nodered.org/uploads/short-url/jl8Crguy93phrgeuIiV7Gbcngmw.json) (2.8 KB)  
When I push "1" will return msg.payload=1  
When I push "0" wil delay 10 seconds and return msg.payload =0

---

<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:** [22 May 2024 09:41 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/4 "2024-05-22T09:41:01Z")

</div>

To me you can't do that in the `delay` node.

You will need a `function` node before it to change the `msg.delay` value.

(But that's just how I read the post)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 May 2024 09:53 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/5 "2024-05-22T09:53:54Z")

</div>

> [@ThaiMinh120](#):
>
> When I push "1" will return msg.payload=1  
> When I push "0" wil delay 10 seconds and return msg.payload =0

So as i said before, you can use switch node and delay node - no functions required.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d713fb133505b016222e8337ebe150e7a3001b77.png)

```auto
[{"id":"c8637d2561ddb48e","type":"debug","z":"e532e271879e8af2","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1760,"y":260,"wires":[]},{"id":"78b159310530c451","type":"debug","z":"e532e271879e8af2","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1760,"y":300,"wires":[]},{"id":"582697e655c15bf4","type":"inject","z":"e532e271879e8af2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":1210,"y":260,"wires":[["8e9928861d612c8c"]]},{"id":"bdc92c9e8060ec98","type":"inject","z":"e532e271879e8af2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":1210,"y":300,"wires":[["8e9928861d612c8c"]]},{"id":"1bf04240e9a4b86e","type":"delay","z":"e532e271879e8af2","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1610,"y":300,"wires":[["78b159310530c451"]]},{"id":"8e9928861d612c8c","type":"switch","z":"e532e271879e8af2","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1410,"y":280,"wires":[["c8637d2561ddb48e"],["1bf04240e9a4b86e"]]}]

```

Is that better?

* * *

PS: for small demo flows, it is preferable to simply paste the flow into a code block like I did above.

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [22 May 2024 12:59 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/6 "2024-05-22T12:59:42Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/fad786ac5bb1fb3d08201a4f2b78f73bf8cf1420.png)  
So when it's "0" and I push "1" it gets error 1 0 10 like in the picture  
My Firebase samples continuously, every 3 seconds  
What do you think about the setTimeout command?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 May 2024 13:14 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/7 "2024-05-22T13:14:33Z")

</div>

> [@ThaiMinh120](#):
>
> What do you think about the setTimeout command?

I guess you mean in a function node? Well, there is no need for it as there are dedicated nodes (like the delay and trigger nodes) for this. Using a function for something like a delay is just hiding (and therfore losing) the benefits of Flow Based Programming.

> [@ThaiMinh120](#):
>
> My Firebase samples continuously, every 3 seconds

ok, but I dont understand what you are asking.

* * *

Instead of posting small demo flows or asking very specific questions about delays etc, you should try to tell us what the actual goal is. There may be an existing node or better pattern you can use.

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [22 May 2024 13:28 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/8 "2024-05-22T13:28:51Z")

</div>

I want write "0" "1" from firebase to relay.  
When firebase push "1", relay ON.  
when firebase push "0" wil delay 10s and relay OFF.  
To your flow, when it's "0" and when firebase push "1" it's error 1 0 1 0 like picture

 ![Screenshot 2024-05-22 202226](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9c98383721c712a44dab621f24ec3ba1fc8e870.png)  
In this image, the number of read delays is 3 times because I set Firebase to sample every 3 seconds, but I only want it to read once. Otherwise, it will error with 1 0 1 0 as shown above, and the relay will turn ON and OFF continuously. So bad ☹

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 May 2024 14:01 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/9 "2024-05-22T14:01:23Z")

</div>

ok, so now we know what you want we can help you

You can achieve this several ways. One way is to an RBE (filter) node. It can block unless a value has changed.

Demo:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b4123f0488ebfe1245d289eced0ca14c431c514.png)

```auto
[{"id":"78b159310530c451","type":"debug","z":"b80ad2c292e3e84c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":280,"wires":[]},{"id":"582697e655c15bf4","type":"inject","z":"b80ad2c292e3e84c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":150,"y":260,"wires":[["8e9928861d612c8c"]]},{"id":"bdc92c9e8060ec98","type":"inject","z":"b80ad2c292e3e84c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":150,"y":300,"wires":[["8e9928861d612c8c"]]},{"id":"8e9928861d612c8c","type":"switch","z":"b80ad2c292e3e84c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":280,"wires":[["925b0d49ba99de1c","a1f96e36bfa2ac70"],["92142dd4cf3952c8"]]},{"id":"3dbf543bccb30c66","type":"comment","z":"b80ad2c292e3e84c","name":"Simulate Firebase","info":"","x":150,"y":340,"wires":[]},{"id":"7d3ce5228fcc266b","type":"comment","z":"b80ad2c292e3e84c","name":"Only send \\n if value \\n changes","info":"","x":580,"y":220,"wires":[]},{"id":"925b0d49ba99de1c","type":"rbe","z":"b80ad2c292e3e84c","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":570,"y":280,"wires":[["78b159310530c451"]]},{"id":"92142dd4cf3952c8","type":"trigger","z":"b80ad2c292e3e84c","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":570,"y":340,"wires":[["925b0d49ba99de1c"]]},{"id":"c25e2eb4601bb297","type":"comment","z":"b80ad2c292e3e84c","name":"send reset:true \\n to clear any \\n ongoing delay","info":"","x":380,"y":400,"wires":[]},{"id":"a1f96e36bfa2ac70","type":"function","z":"b80ad2c292e3e84c","name":"send reset","func":"return {reset:true}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":340,"wires":[["92142dd4cf3952c8"]]}]

```

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [22 May 2024 14:44 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/10 "2024-05-22T14:44:04Z")

</div>

Oh. That's so good.  
But i don't want clear value previous  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b190d6be0ac2e944cc9cf53fbabbba6e25a81434.png)  
do you have anyway?

---

<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 May 2024 15:39 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/11 "2024-05-22T15:39:40Z")

</div>

> [@ThaiMinh120](#):
>
> i don't want clear value previous

What do you want to happen if 1 is pressed before the 10 seconds has run down?

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [23 May 2024 02:37 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/12 "2024-05-23T02:37:42Z")

</div>

Only when sending "0" will there be a delay of 10 seconds, but when sending "1" there will be no delay and the previous values ​​will not be cleared.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 May 2024 02:46 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/13 "2024-05-23T02:46:17Z")

</div>

> [@ThaiMinh120](#):
>
> Only when sending "0" will there be a delay of 10 seconds, but when sending "1" there will be no delay

That is exactly what the solution does.

> [@ThaiMinh120](#):
>
> y and the previous values ​​will not be cleared

What previous values?

Have you actually tried the solution & checked the output?

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [23 May 2024 02:56 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/14 "2024-05-23T02:56:19Z")

</div>

Yes, i tried  
Yesterday I tried it and the value was clear, but today it's normal.  
When it happens, I will record a video for you to see.

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [23 May 2024 03:09 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/15 "2024-05-23T03:09:47Z")

</div>

If I remove the "send reset" function, will it have any effect?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/e/eeb279b3e5004e618c0443d20ef41b7049f0e3ca.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 May 2024 06:24 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/16 "2024-05-23T06:24:16Z")

</div>

Yes. Of course.

If you get 1, 0, 1  
The delay will not be cancelled and the 0 will come through

You know you can import a 2nd copy of my demo and try it for yourself - just use debug nodes to see what happens without actually sending the output to the relay?

anyhow, here is what you would see if firebase sends 1,0,1,1

| Time | Firebase | output changed | info |
| --- | --- | --- | --- |
| 00:00:00 | 1 | 1 | |
| 00:00:03 | 0 | | nothing is output, still state 1, but timer is started |
| 00:00:06 | 1 | | nothing is output because RBE filter has not recorded a different value, still output is 1 |
| 00:00:09 | 1 | | nothing is output because RBE filter has not recorded a different value, still output is 1 |
| 00:00:10 | | 0 | timer emitted it's zero because it was not reset |

---

<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:** [23 May 2024 06:24 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/17 "2024-05-23T06:24:28Z")

</div>

No need for a video. As a debug node showing the output of the firebase node and show us the result. Then we can see the results.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [23 May 2024 07:34 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/18 "2024-05-23T07:34:41Z")

</div>

> [@ThaiMinh120](#):
>
> In this image, the number of read delays is 3 times because I set Firebase to sample every 3 seconds,

Note that an updated Firebase palette has a node being triggered by events (`value changes` for this one) in order not to read every x sec.

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [23 May 2024 08:49 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/19 "2024-05-23T08:49:29Z")

</div>

Yes, I get you  
I really appreciate your support,  
Thank you sir.

---

<div class="post-metadata">

**Author:** ![ThaiMinh120](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thaiminh120/32/90099_2.png) [@ThaiMinh120](https://discourse.nodered.org/u/ThaiMinh120)\
**Post date:** [23 May 2024 08:58 UTC](https://discourse.nodered.org/t/delay-time-node-red/88159/20 "2024-05-23T08:58:55Z")

</div>

Oh I will review it.  
Thank you sir.

[Next page](https://discourse.nodered.org/t/delay-time-node-red/88159.md?page=2)
