Delay node problem with override

#1

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.

[{"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}]
0 Likes

#2

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

0 Likes

#3

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.

0 Likes

#4

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

0 Likes

#5

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.

0 Likes

#6

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.

0 Likes

#7

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.

0 Likes

#8

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

0 Likes

#9

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.

0 Likes

#10

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

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

#11

Thanks. I will test it.

0 Likes

#12

Or maybe a simple trigger node -

[{"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}]
1 Like

#13

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

0 Likes

#14

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

0 Likes

#15

@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.

0 Likes

#16

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.

0 Likes