# Delay node problem with override

**URL:** <https://discourse.nodered.org/t/delay-node-problem-with-override/8687>\
**Category:** General\
**Created:** [6 March 2019 22:51 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687 "2019-03-06T22:51:08Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratomas](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ratomas](https://discourse.nodered.org/u/ratomas)\
**Post date:** [6 March 2019 22:51 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/1 "2019-03-06T22:51:08Z")

</div>

Hi.  
I tried to set override for delay. When I have msg.payload = true ( without delay ), for msg.payload = false ( defined delay ). Off delay works without problem, but for on delay I have at beginning flip-flop signal true/false, after few seconds expected true signal.

```auto
[{"id":"4a84373a.f8db8","type":"debug","z":"9fcddc0a.9d9f9","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":790,"y":100,"wires":[]},{"id":"b07eec1d.33693","type":"function","z":"9fcddc0a.9d9f9","name":"Delay","func":"state = String(msg.payload);\nvar delay\n\nif ( state == \"true\" )\n {\n delay = 100;\n msg.delay = delay;\n }\n\nelse if ( state == \"false\" )\n {\n delay = 20000;\n msg.delay = delay;\n }\n\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":100,"wires":[["6f3c03c4.b69114"]],"outputLabels":["cmd"]},{"id":"6f3c03c4.b69114","type":"delay","z":"9fcddc0a.9d9f9","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":620,"y":100,"wires":[["4a84373a.f8db8"]]},{"id":"3dc3447d.20792c","type":"ui_switch","z":"9fcddc0a.9d9f9","name":"","label":"switch","group":"8c41b690.380cb8","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":270,"y":100,"wires":[["b07eec1d.33693"]]},{"id":"e58c5d67.44dd3","type":"inject","z":"9fcddc0a.9d9f9","name":"","topic":"","payload":"","payloadType":"date","repeat":"2","crontab":"","once":true,"onceDelay":0.1,"x":110,"y":100,"wires":[["3dc3447d.20792c"]]},{"id":"8c41b690.380cb8","type":"ui_group","z":"","name":"Timer","tab":"aefaddb2.7073a8","order":1,"disp":true,"width":"6","collapse":false},{"id":"aefaddb2.7073a8","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":2}]

```

---

<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:** [7 March 2019 08:40 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/2 "2019-03-07T08:40:46Z")

</div>

Can you repost your flow, your output is not correct.

---

<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:** [7 March 2019 08:43 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/3 "2019-03-07T08:43:45Z")

</div>

Please see this post for how to post a flow here in a way that will make it importable. You can go back and edit your previous post accordingly.

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<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:** [7 March 2019 10:08 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/4 "2019-03-07T10:08:35Z")

</div>

It seems to be doing what I would expect. Please explain what you expect to see and what you are seeing with that flow.

---

<div class="post-metadata">

**Author:** ![ratomas](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ratomas](https://discourse.nodered.org/u/ratomas)\
**Post date:** [7 March 2019 13:12 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/5 "2019-03-07T13:12:56Z")

</div>

I need on delay override with 0 seconds and off delay override with 20 seconds. When I switch off, the message is delayed. I have false message after 20 seconds. When I switch on, the message is without delay. Problem is that I have for few seconds flip-flop value of message after switch on. Payload message is changing false / true. Stable true value of payload message is after 10 seconds.

---

<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:** [7 March 2019 17:27 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/6 "2019-03-07T17:27:29Z")

</div>

Nice one! This certainly needed the brain to be engaged.  
Consider the situation with the switch off. Every two seconds a 'false' message is given to the delay node with the instruction to delay it for 20 seconds. So after 20 seconds there is a queue of about 10 'false' messages being delayed, each two seconds apart.  
Now switch the switch.  
The next message ('true') has a delay of 0.1 seconds specified so it passes through quickly, overtaking the 'true' messages already in the queue. Then follows a sequence of 'false' messages two seconds apart with only short delays specified, so they all overtake the 'true' ones already in the queue till the queue runs down, causing the apparent flip-flop you are seeing.

---

<div class="post-metadata">

**Author:** ![ratomas](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ratomas](https://discourse.nodered.org/u/ratomas)\
**Post date:** [8 March 2019 10:44 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/7 "2019-03-08T10:44:37Z")

</div>

Thank you for your description. Can you advice me simple way, how to create on delay and off delay without flip-flop. I am not sure if delay node is good choice.

---

<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:** [8 March 2019 10:52 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/8 "2019-03-08T10:52:54Z")

</div>

Could you explain the reason you want to do this, I suspect there may be a better way of solving the underlying requirement.

---

<div class="post-metadata">

**Author:** ![ratomas](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ratomas](https://discourse.nodered.org/u/ratomas)\
**Post date:** [8 March 2019 10:58 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/9 "2019-03-08T10:58:45Z")

</div>

I have relay controlled fan in greenhouse. When I switch on relay, I need without delay. When I switch off, I need defined time for off delay.

---

<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:** [8 March 2019 11:25 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/10 "2019-03-08T11:25:55Z")

</div>

Try this. It delays the off signal (by 10 secs in this case) but not the on. It stops the flip-flop by resetting the delay node in the case of an On signal. Note that the output is taken both from the delay node and o/p two of the Switch node.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/281dd23b13c5556cc0ad2a743b3b3e7316bfbed9.png)

````auto
[{"id":"95a3f281.ab2b58","type":"debug","z":"cfa39195.99bef","name":"This is the output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":556,"y":367,"wires":[]},{"id":"12c48dd5.8d741a","type":"delay","z":"cfa39195.99bef","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":502,"y":195,"wires":[["95a3f281.ab2b58"]]},{"id":"ce40251b.36dc5","type":"ui_switch","z":"cfa39195.99bef","name":"","label":"switch","group":"fa621d1a.e18c38","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":285,"y":116,"wires":[["c225a8e9.e0c37"]]},{"id":"c225a8e9.e0c37","type":"switch","z":"cfa39195.99bef","name":"","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":165.5,"y":222,"wires":[["12c48dd5.8d741a"],["95a3f281.ab2b58","e2d950a2.f726d"]]},{"id":"e2d950a2.f726d","type":"change","z":"cfa39195.99bef","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":391.5,"y":242,"wires":[["12c48dd5.8d741a"]]},{"id":"fa621d1a.e18c38","type":"ui_group","z":"","name":"Timer","tab":"deb79714.b3088","order":1,"disp":true,"width":"6","collapse":false},{"id":"deb79714.b3088","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":2}]```
````

---

<div class="post-metadata">

**Author:** ![ratomas](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ratomas](https://discourse.nodered.org/u/ratomas)\
**Post date:** [8 March 2019 11:59 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/11 "2019-03-08T11:59:15Z")

</div>

Thanks. I will test it.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [8 March 2019 12:22 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/12 "2019-03-08T12:22:43Z")

</div>

Or maybe a simple trigger node -

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f3634742667592781ba089dee015f8204083d448.png)

```auto
[{"id":"ed12c1bf.3428a","type":"trigger","z":"f86be7c2.1183b8","op1":"","op2":"off","op1type":"nul","op2type":"str","duration":"10","extend":false,"units":"s","reset":"on","bytopic":"all","name":"","x":890,"y":580,"wires":[["a96f1c44.2f153"]]},{"id":"a96f1c44.2f153","type":"debug","z":"f86be7c2.1183b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1090,"y":540,"wires":[]},{"id":"54c827ef.592b08","type":"switch","z":"f86be7c2.1183b8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":870,"y":540,"wires":[["a96f1c44.2f153"]]},{"id":"7a50ec33.2364f4","type":"ui_switch","z":"f86be7c2.1183b8","name":"","label":"switch","tooltip":"","group":"d69449d4.8ad738","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":710,"y":540,"wires":[["54c827ef.592b08","ed12c1bf.3428a"]]},{"id":"d69449d4.8ad738","type":"ui_group","z":"f86be7c2.1183b8","name":"Default","tab":"b5f4b6fa.52a578","order":1,"disp":true,"width":"9","collapse":false},{"id":"b5f4b6fa.52a578","type":"ui_tab","z":"f86be7c2.1183b8","name":"Home","icon":"dashboard","order":1}]

```

---

<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:** [8 March 2019 12:34 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/13 "2019-03-08T12:34:26Z")

</div>

I like that better, I hadn't realised that you can use a payload value to reset the trigger.

---

<div class="post-metadata">

**Author:** ![ratomas](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ratomas](https://discourse.nodered.org/u/ratomas)\
**Post date:** [8 March 2019 19:30 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/14 "2019-03-08T19:30:04Z")

</div>

I have tested both versions. Colin's solution is exactly what I want. Thanks.

---

<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:** [8 March 2019 21:54 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/15 "2019-03-08T21:54:04Z")

</div>

@dceejay's solution is simpler and neater, so personally I would use that one. It doesn't exactly do what you want as you have true and false coming from the switch whereas his has on and off. I am sure if you look at it you will see how it works and be able to tweak the node settings appropriately. I also hope you have not just used mine because it works, without understanding _how_ it works.

---

<div class="post-metadata">

**Author:** ![ratomas](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ratomas](https://discourse.nodered.org/u/ratomas)\
**Post date:** [9 March 2019 14:05 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/16 "2019-03-09T14:05:54Z")

</div>

I used inject node with timestamp ( repeat interval 2 seconds ) instead of switch in @dceejay's solution and it wasn't according my expectation. It was no problem, I changed true/false instead of on/off. I was thinking about how it works.

---

<div class="post-metadata">

**Author:** ![gramtech](https://avatars.discourse-cdn.com/v4/letter/g/d2c977/32.png) [@gramtech](https://discourse.nodered.org/u/gramtech)\
**Post date:** [20 July 2020 08:42 UTC](https://discourse.nodered.org/t/delay-node-problem-with-override/8687/17 "2020-07-20T08:42:58Z")

</div>

Nice, thank you for this, solved my problem with delays!
