Delay time node red

image
Help me make a delay function node red for this picture.
Tks.

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

flows (1).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

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)

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

[{"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.

1 Like


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?

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.

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.

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


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 :frowning:

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:

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

Oh. That's so good.
But i don't want clear value previous
image
do you have anyway?

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

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.

That is exactly what the solution does.

What previous values?

Have you actually tried the solution & checked the output?

1 Like

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.

If I remove the "send reset" function, will it have any effect?
image

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
1 Like

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.

1 Like

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.

1 Like

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

Oh I will review it.
Thank you sir.