Timing out if flow has been idle for x minutes

Hi, I need some help adding timeout if a flow has not been running for x minutes.
I have tried several of the node packages with timeouts. but I cant figure out how to make it work automatically.

I am trying to set a timeout which should trigger if the flow here has not been ran in x minutes.
As you can see here: Im trying to see if data has come to the timout, if not in 1 minute it should trigger.

[{"id":"f8d6f940.723648","type":"serial out","z":"cc7a9a18.8f7298","name":"TO Arduino","serial":"4cae3faa.f97f5","x":1510,"y":1380,"wires":[]},{"id":"82da9662.e16018","type":"function","z":"cc7a9a18.8f7298","name":"Fan control","func":"const Temp = msg.payload;\nconst override = global.get(\"AutoManual_switch\") || 0;\nconst minTemp = global.get(\"minTemp\") || 23.5;\nconst maxTemp = global.get(\"maxTemp\") || 29;\nconst fanstate = global.get(\"FanState\");\n\n\nif (override != 1) {\n    if (Temp <= minTemp && fanstate !== 0) {\n        msg.payload = 2;\n        global.set(\"FanState\", msg.payload);\n        return msg;\n    } else if (Temp >= maxTemp && fanstate != 1) {\n        msg.payload = 1;\n        global.set(\"FanState\", msg.payload);\n        return msg;\n    } else {\n        return null;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":950,"y":1260,"wires":[["a3028222.3546c","126467d.f504898"]]},{"id":"74a6c5de.293aac","type":"change","z":"cc7a9a18.8f7298","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"Auto","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"Manual","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":980,"wires":[["981871e6.87e13"]]},{"id":"8de87af7.9abc58","type":"change","z":"cc7a9a18.8f7298","name":"Auto/Manual var","rules":[{"t":"set","p":"AutoManual_switch","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":1020,"wires":[[]]},{"id":"3e06858f.5285ba","type":"change","z":"cc7a9a18.8f7298","name":"FanState var","rules":[{"t":"set","p":"FanState","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":1220,"wires":[[]]},{"id":"a3028222.3546c","type":"change","z":"cc7a9a18.8f7298","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"2","fromt":"num","to":"Off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":1160,"wires":[["c8153aaa.5ad218"]]},{"id":"c8153aaa.5ad218","type":"ui_text","z":"cc7a9a18.8f7298","group":"ae2b69cd.4c98c8","order":6,"width":0,"height":0,"name":"OnOFF Text","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1430,"y":1160,"wires":[]},{"id":"981871e6.87e13","type":"ui_text","z":"cc7a9a18.8f7298","group":"ae2b69cd.4c98c8","order":5,"width":0,"height":0,"name":"manualText","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1430,"y":980,"wires":[]},{"id":"8291d9d6.21a488","type":"function","z":"cc7a9a18.8f7298","name":"turn on override","func":"const override = global.get(\"AutoManual_switch\") || 0;\nif(override === 0){\n    msg.payload = 1;\n    return msg;\n} else {\n    return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1240,"y":1080,"wires":[["74a6c5de.293aac","8de87af7.9abc58"]]},{"id":"3936c20f.665f7e","type":"ui_dropdown","z":"cc7a9a18.8f7298","name":"","label":"","tooltip":"","place":"Select option","group":"ae2b69cd.4c98c8","order":4,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"AUTO","value":"auto","type":"str"},{"label":"ON","value":1,"type":"num"},{"label":"OFF","value":"2","type":"str"}],"payload":"","topic":"","x":810,"y":1100,"wires":[["48120fe8.2281b"]]},{"id":"48120fe8.2281b","type":"switch","z":"cc7a9a18.8f7298","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"auto","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":970,"y":1100,"wires":[["74a6c5de.293aac","75707cd1.cfda84"],["8291d9d6.21a488","a3028222.3546c","3e06858f.5285ba","126467d.f504898"]]},{"id":"75707cd1.cfda84","type":"change","z":"cc7a9a18.8f7298","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":1020,"wires":[["8de87af7.9abc58"]]},{"id":"c229f410.3b8b68","type":"inject","z":"cc7a9a18.8f7298","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"auto","payloadType":"str","x":630,"y":1100,"wires":[["3936c20f.665f7e"]]},{"id":"126467d.f504898","type":"change","z":"cc7a9a18.8f7298","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"2","fromt":"num","to":"<fanoff>","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"<fanon>","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":1380,"wires":[["f8d6f940.723648","e9e40123.9223c"]]},{"id":"2681e91d.b3f846","type":"inject","z":"cc7a9a18.8f7298","name":"Turn on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":640,"y":980,"wires":[["3936c20f.665f7e"]]},{"id":"7e6971be.9fb61","type":"inject","z":"cc7a9a18.8f7298","name":"Turn off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"str","x":640,"y":920,"wires":[["3936c20f.665f7e"]]},{"id":"e9e40123.9223c","type":"timeouttrigger","z":"cc7a9a18.8f7298","ontimeouttype":"str","ontimeoutval":"<ledon>","duration":"1","units":"min","name":"","x":1450,"y":1520,"wires":[["5b4022d8.ccb39c","f8d6f940.723648"]]},{"id":"5b4022d8.ccb39c","type":"debug","z":"cc7a9a18.8f7298","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1680,"y":1540,"wires":[]},{"id":"d5626b05.e68a58","type":"inject","z":"cc7a9a18.8f7298","name":"Turn fan on after 1 minute of not being on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<fanon>","payloadType":"str","x":1140,"y":1520,"wires":[["e9e40123.9223c"]]},{"id":"4cae3faa.f97f5","type":"serial-port","z":"","serialport":"/dev/ttyACM0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"ae2b69cd.4c98c8","type":"ui_group","z":"","name":"Temperatur","tab":"9cd27c9a.6e166","order":1,"disp":false,"width":"6","collapse":false},{"id":"9cd27c9a.6e166","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Thanks for any help on this

The usual way to run a watchdog like this is to feed your event into a Trigger node set to Send Nothing then after x minutes send the timeout message. Also set Extend Delay if new message arrives. Then every time a message arrives it will restart the timer, but if the time elapses with no message incoming then the timeout message will be sent.
If you want it to start timing when node red restarts even if no event arrives then connect an Inject node set to fire once on startup in order to kick it into life.

1 Like

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