Trigger a Variable after a time (based on a input value)

Hello,

I'm a complete newbie...
I have some experience in IEC61131 (Beckhoff Twincat) but NodeRed is absolutely new for me. My installation runs on a Raspberry 3B.
Here's what I want to realize:
If the value of a variable is longer than for example 3 seconds > 0 then the output should be true. If the value of the variable falls to 0 again within the given time (3 sec.), the output remains false.
Could you perhaps give me a little hint...
Thanks a lot!

best regards

good_mike

Hi, welcome aboard.

look at the trigger node - set it to send 0 - then wait three seconds - then send 1 - but set to extend if another input arrives (so it will stay at 0)

that's my solution so far....
But the output gos to TRUE even if the Input is at 0 within 5 secons

[{"id":"4ed5c212.1e810c","type":"function","z":"35c5b282.47cf2e","name":"","func":"if(msg.payload >0){\n    msg.payload=true;\n}else{\n    msg.payload = false;\n}\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":240,"wires":[["23de7783.6b0108"]]}]

I think you might not have copied all of your flow - that just seems to contain a function node

ah, sorry: newbie.... :slight_smile:

[{"id":"35c5b282.47cf2e","type":"tab","label":"Übungen","disabled":false,"info":""},{"id":"c889e497.627288","type":"debug","z":"35c5b282.47cf2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":930,"y":240,"wires":[]},{"id":"4ed5c212.1e810c","type":"function","z":"35c5b282.47cf2e","name":"","func":"if(msg.payload >0){\n    msg.payload=true;\n}else{\n    msg.payload = false;\n}\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":240,"wires":[["23de7783.6b0108"]]},{"id":"a9148825.547ac8","type":"ui_numeric","z":"35c5b282.47cf2e","name":"","label":"numeric","tooltip":"","group":"2acf9945.528086","order":2,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":10,"step":1,"x":440,"y":240,"wires":[["4ed5c212.1e810c"]]},{"id":"23de7783.6b0108","type":"trigger","z":"35c5b282.47cf2e","op1":"false","op2":"","op1type":"bool","op2type":"pay","duration":"5","extend":false,"units":"s","reset":"True","bytopic":"all","name":"","x":750,"y":240,"wires":[["c889e497.627288"]]},{"id":"2acf9945.528086","type":"ui_group","z":"","name":"E-Mail-Adressen","tab":"73fccdec.21cd94","disp":true,"width":"6","collapse":false},{"id":"73fccdec.21cd94","type":"ui_tab","z":"","name":"Sonstiges","icon":"dashboard","disabled":false,"hidden":false}]

Ah right. So then also set it to reset when it sees a 0

I do not know I how I can reset it.

Maybe I need a short demo code....

Up to now, it does not work as it should. I only want to output "TRUE" if the input of the trigger function is "TRUE" for more than 5 seconds. If the input of the trigger function is "FALSE" again before the 5 seconds are reached, the output should remain on "FALSE". Like the classic TON function in IEC61131 / Twincat.

Look at the info panel for the node, then use a Switch to detect the false condition then pass that to a Change node to build the reset message to pass to the trigger node.

sorry, but this I do not understand - I'm complete new in node red....

I try this, but this is also not working:

[{"id":"35c5b282.47cf2e","type":"tab","label":"Übungen","disabled":false,"info":""},{"id":"c889e497.627288","type":"debug","z":"35c5b282.47cf2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":930,"y":240,"wires":[]},{"id":"4ed5c212.1e810c","type":"function","z":"35c5b282.47cf2e","name":"","func":"if(msg.payload >0){\n    msg.payload=true;\n}else{\n    msg.payload = false;\n}\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":240,"wires":[["23de7783.6b0108","2ff35f97.3d37f"]]},{"id":"a9148825.547ac8","type":"ui_numeric","z":"35c5b282.47cf2e","name":"","label":"numeric","tooltip":"","group":"2acf9945.528086","order":2,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"","format":"{{value}}","min":0,"max":10,"step":1,"x":400,"y":240,"wires":[["4ed5c212.1e810c","b9cbcbeb.205688"]]},{"id":"23de7783.6b0108","type":"trigger","z":"35c5b282.47cf2e","op1":"false","op2":"","op1type":"bool","op2type":"pay","duration":"5","extend":false,"units":"s","reset":"True","bytopic":"all","name":"","x":750,"y":240,"wires":[["c889e497.627288"]]},{"id":"2ff35f97.3d37f","type":"debug","z":"35c5b282.47cf2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":770,"y":140,"wires":[]},{"id":"b9cbcbeb.205688","type":"debug","z":"35c5b282.47cf2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":570,"y":80,"wires":[]},{"id":"dd856326.5bdd2","type":"inject","z":"35c5b282.47cf2e","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":470,"y":360,"wires":[["afb93624.f23c18","7b4bfd5d.5d6864"]]},{"id":"735ac9b8.3f40c8","type":"debug","z":"35c5b282.47cf2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1070,"y":360,"wires":[]},{"id":"afb93624.f23c18","type":"debug","z":"35c5b282.47cf2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":650,"y":300,"wires":[]},{"id":"7b4bfd5d.5d6864","type":"trigger","z":"35c5b282.47cf2e","op1":"false","op2":"true","op1type":"bool","op2type":"bool","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":810,"y":360,"wires":[["735ac9b8.3f40c8"]]},{"id":"4ee8bc33.c51db4","type":"inject","z":"35c5b282.47cf2e","name":"","topic":"","payload":"msg.reset","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":480,"y":420,"wires":[["7b4bfd5d.5d6864"]]},{"id":"2acf9945.528086","type":"ui_group","z":"","name":"E-Mail-Adressen","tab":"73fccdec.21cd94","disp":true,"width":"6","collapse":false},{"id":"73fccdec.21cd94","type":"ui_tab","z":"","name":"Sonstiges","icon":"dashboard","disabled":false,"hidden":false}]

Try this, very simple flow with trigger. As long zero's are passed the module will be true, if no zero for three seconds then it will be false.

[{"id":"fcbb8937.0bc388","type":"trigger","z":"a936faf0.abbd88","op1":"false","op2":"true","op1type":"bool","op2type":"bool","duration":"3","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":500,"y":600,"wires":[["c0c665a6.852678"]]},{"id":"8d418d1e.855fe","type":"switch","z":"a936faf0.abbd88","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":320,"y":600,"wires":[["fcbb8937.0bc388"]]},{"id":"c0c665a6.852678","type":"debug","z":"a936faf0.abbd88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":600,"wires":[]},{"id":"a3fb03e6.4680a","type":"inject","z":"a936faf0.abbd88","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":600,"wires":[["8d418d1e.855fe"]]}]

Thanks - I will learn with this example!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.