Can two instances of a scheduled flow run concurrently?

Hello - I have a flow that is executed every 5 minutes (inject node) that pings a device and depending on the response (if it is up or not), shuts down (or restarts) other devices. I wanted to avoid a situation where a second instance of the flow started up while the first one was still executing, so I set a global variable to true in the begining and false at the end.

However, when I was testing the flow, it appears that the second instance does not run concurrently but waits for the first one to complete. To do the test, I put in a 10 sec delay in the middle of the flow and manually triggered the inject node, but I never saw an output from the debug node that was monitoring the global variable and ending the flow if it was already running.

Is it safe to assume that the scheduled flows will not execute concurrently? If needed, is there a better way to prevent this if from happening? What I am trying to avoid is one instance trying to shut down the device while the other tries to restart it.

Thanks for your help.

How can a second instance of the flow start up before the first has finished if it only triggers every 5 minutes? Can it take more than 5 minutes to run?

It could, particularly if it is not going down the "happy" path and needs to stop or restart some devices.

Background: The use case is to shut down my home automation hub if there is a power outage. It is connected to a small power supply but if it is not shut down from the API or the UI, the internal db can get corrupted. So I ping two devices on my internal network that are not connected to a UPS and if both don't respond, the flow shuts down the hub. There is a delay between the first and the second ping for about 3 minutes just in case there is a brief power glitch and it takes a bit of time for the device to shut down.

I could increase the trigger interval but based on the testing I did I wanted to see if I was overthinking the GV part.

Can you export your flow please so we can see what you have done?

Yeah - it's got a lot of stuff that is specific to my use case and a few contrib nodes... hopefully, it will make sense.

[{"id":"bce2c6bb.b4cb4","type":"subflow","name":"Restart Hubitat","info":"","category":"","in":[{"x":31.25,"y":84.25000190734863,"wires":[{"id":"cd006ff3.e1961"}]}],"out":[],"env":[],"color":"#DDAA99"},{"id":"bdb9017c.09a618","type":"kasa","z":"bce2c6bb.b4cb4","name":"Hubitat Plug - Get Info","device":"192.168.1.128","interval":60000,"eventInterval":15000,"payload":"getQuickInfo","payloadType":"info","debug":false,"x":148.74989318847656,"y":344.00000619888306,"wires":[["e34034b1.600848"]]},{"id":"e34034b1.600848","type":"change","z":"bce2c6bb.b4cb4","name":"Get Switch State","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.sysInfo.relay_state","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":371.74989318847656,"y":344.00000619888306,"wires":[["dec01cba.85c768"]]},{"id":"dec01cba.85c768","type":"switch","z":"bce2c6bb.b4cb4","name":"On or Off?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":571.7498931884766,"y":344.00000619888306,"wires":[["10dab972.e6379f"],["21874281.6eeade"]]},{"id":"10dab972.e6379f","type":"change","z":"bce2c6bb.b4cb4","name":"Turn On Switch","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":763.7498931884766,"y":284.00000619888306,"wires":[["48082d5a.f1b034"]]},{"id":"21874281.6eeade","type":"change","z":"bce2c6bb.b4cb4","name":"Turn Off Switch","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":763.7498931884766,"y":404.00000619888306,"wires":[["5bd13715.58b1c"]]},{"id":"bd2a9ace.5c6238","type":"delay","z":"bce2c6bb.b4cb4","name":"Wait for 5 secs","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1177.7498931884766,"y":404.00000619888306,"wires":[["10dab972.e6379f"]]},{"id":"5bd13715.58b1c","type":"kasa","z":"bce2c6bb.b4cb4","name":"Hubitat Plug - Off","device":"192.168.1.128","interval":60000,"eventInterval":15000,"payload":"getQuickInfo","payloadType":"info","debug":false,"x":974.7498931884766,"y":404.00000619888306,"wires":[["bd2a9ace.5c6238"]]},{"id":"48082d5a.f1b034","type":"kasa","z":"bce2c6bb.b4cb4","name":"Hubitat Plug - On","device":"192.168.1.128","interval":60000,"eventInterval":15000,"payload":"getQuickInfo","payloadType":"info","debug":false,"x":973.7498931884766,"y":284.00000619888306,"wires":[["45868e51.b86bf"]]},{"id":"45868e51.b86bf","type":"delay","z":"bce2c6bb.b4cb4","name":"Wait for 2 minutes","pauseType":"delay","timeout":"2","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1180.7498931884766,"y":283.00000619888306,"wires":[["c805956c.7c393"]]},{"id":"cd006ff3.e1961","type":"ping","z":"bce2c6bb.b4cb4","mode":"triggered","name":"Ping Hubitat Plug","host":"192.168.1.128","timer":"20","inputs":1,"x":161.5000228881836,"y":84.25000858306885,"wires":[["b3f8f7aa.ead33"]]},{"id":"b3f8f7aa.ead33","type":"switch","z":"bce2c6bb.b4cb4","name":"Is Plug Reachable?","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":361.5000190734863,"y":84.00000953674316,"wires":[["4e72e09b.25224"],["44276007.209ce8"]]},{"id":"c805956c.7c393","type":"ping","z":"bce2c6bb.b4cb4","mode":"triggered","name":"Ping Hubitat Hub","host":"192.168.1.113","timer":"20","inputs":1,"x":1386.7498931884766,"y":283.00000619888306,"wires":[["68795442.0f8824"]]},{"id":"68795442.0f8824","type":"switch","z":"bce2c6bb.b4cb4","name":"Is Hubitat Up?","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1574.7498931884766,"y":283.00000619888306,"wires":[["b5b2276d.fa2e8"],["34dcea6a.fc5646"]]},{"id":"d630708e.15599","type":"moment","z":"bce2c6bb.b4cb4","name":"","topic":"","input":"","inputType":"date","inTz":"America/Chicago","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD hh:mm A","locale":"en_US","output":"restartDateTime","outputType":"msg","outTz":"America/Chicago","x":2027.7498931884766,"y":281.00000619888306,"wires":[["4c58f3c3.6e4964"]]},{"id":"4c58f3c3.6e4964","type":"function","z":"bce2c6bb.b4cb4","name":"Set Notification Params","func":"//Set error message\n\nvar message = msg.payload;\nvar topic = msg.topic+\" - \"+msg.restartDateTime;\nvar priority = 0; //values are -2,-1,0,1,2\nvar device = \"\"; //Blank device = All\nvar url = \"\";  // url to be included in message\nvar url_title = \"\";// title of URL\nvar sound = \"\"; // notifcation sound\nvar attachmentPath = \"\"; //file path if attachment is included\n\n//Inputs for Notification Subflow\nmsg.payload = message;\nmsg.topic = topic;\nmsg.device = device;\nmsg.priority = priority;\nmsg.url = url;\nmsg.url_title = url_title\nmsg.attachment = attachmentPath;\nmsg.sound = sound;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2269.7498931884766,"y":281.00000619888306,"wires":[["7ffd297d.251e28"]]},{"id":"b5b2276d.fa2e8","type":"change","z":"bce2c6bb.b4cb4","name":"Hubitat Not Up","rules":[{"t":"set","p":"payload","pt":"msg","to":"Unable to restart Hubitat Hub","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"Hub restart failed","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1782.7498931884766,"y":244.00000619888306,"wires":[["d630708e.15599"]]},{"id":"34dcea6a.fc5646","type":"change","z":"bce2c6bb.b4cb4","name":"Hubitat Is Up","rules":[{"t":"set","p":"payload","pt":"msg","to":"Hubitat Hub has been restarted","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"Hubitat Hub is up","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1782.7498931884766,"y":324.00000619888306,"wires":[["d630708e.15599"]]},{"id":"44276007.209ce8","type":"change","z":"bce2c6bb.b4cb4","name":"Get Plug Info","rules":[{"t":"set","p":"payload","pt":"msg","to":"getQuickInfo","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":553.5000190734863,"y":145.00000190734863,"wires":[["bdb9017c.09a618"]]},{"id":"4e72e09b.25224","type":"change","z":"bce2c6bb.b4cb4","name":"Hubitat Plug Not Reachable","rules":[{"t":"set","p":"payload","pt":"msg","to":"Unable to restart Hubitat Hub - Plug is not online","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"Cannot Reach Hubitat Plug","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1748.999855041504,"y":77.00001525878906,"wires":[["d630708e.15599"]]},{"id":"77d54c21.91e3b4","type":"comment","z":"bce2c6bb.b4cb4","name":"No","info":"","x":357.2242202758789,"y":44.843143463134766,"wires":[]},{"id":"f4c55e14.59f95","type":"comment","z":"bce2c6bb.b4cb4","name":"Yes","info":"","x":358.8908996582031,"y":133.17648696899414,"wires":[]},{"id":"6ddc15f6.011ec4","type":"comment","z":"bce2c6bb.b4cb4","name":"Off","info":"","x":588.1408233642578,"y":305.5098023414612,"wires":[]},{"id":"7f4515f0.794c74","type":"comment","z":"bce2c6bb.b4cb4","name":"On","info":"","x":589.807502746582,"y":393.84314584732056,"wires":[]},{"id":"8fb46f39.0f93d","type":"comment","z":"bce2c6bb.b4cb4","name":"No","info":"","x":1614.1407623291016,"y":242.84314584732056,"wires":[]},{"id":"f83efca1.fe4688","type":"comment","z":"bce2c6bb.b4cb4","name":"Yes","info":"","x":1614.1407318115234,"y":333.8431611061096,"wires":[]},{"id":"7ffd297d.251e28","type":"subflow:34d03f0e.2cfc6","z":"bce2c6bb.b4cb4","name":"","x":2524,"y":281,"wires":[]},{"id":"34d03f0e.2cfc6","type":"subflow","name":"Notification Handler","info":"","category":"","in":[{"x":60,"y":80,"wires":[{"id":"e450ca50.a95f18"}]}],"out":[],"env":[],"color":"#DDAA99"},{"id":"d61bf195.44c66","type":"comment","z":"34d03f0e.2cfc6","name":"Notification Subflow","info":"","x":130,"y":20,"wires":[]},{"id":"e450ca50.a95f18","type":"pushover","z":"34d03f0e.2cfc6","name":"Send Notification","device":"","title":"","priority":0,"sound":"","url":"","url_title":"","html":false,"x":210,"y":80,"wires":[]},{"id":"df66407a.c32fe","type":"subflow","name":"Shut Down Hubitat","info":"","category":"","in":[{"x":72.5,"y":86.50000095367432,"wires":[{"id":"995e346f.e734f"}]}],"out":[],"env":[],"color":"#DDAA99"},{"id":"995e346f.e734f","type":"http request","z":"df66407a.c32fe","name":"Shut Down Hub","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://192.168.1.113/hub/shutdown","tls":"","persist":false,"proxy":"","authType":"","x":214.99994659423828,"y":86.25000095367432,"wires":[["ee41888d.f8d94"]]},{"id":"ee41888d.f8d94","type":"moment","z":"df66407a.c32fe","name":"","topic":"","input":"","inputType":"date","inTz":"America/Chicago","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD hh:mm A","locale":"en_US","output":"shutdownDateTime","outputType":"msg","outTz":"America/Chicago","x":432.4999465942383,"y":86.75000095367432,"wires":[["da4727ee.dc8808"]]},{"id":"da4727ee.dc8808","type":"function","z":"df66407a.c32fe","name":"Set Notification Params","func":"//Set error message\n\nvar message = \"Power outage detected - Hubitat shutting down\";\nvar topic = \"Hub Shutdown - \"+msg.shutdownDateTime;\nvar priority = 0; //values are -2,-1,0,1,2\nvar device = \"\"; //Blank device = All\nvar url = \"\";  // url to be included in message\nvar url_title = \"\";// title of URL\nvar sound = \"\"; // notifcation sound\nvar attachmentPath = \"\"; //file path if attachment is included\n\n//Inputs for Notification Subflow\nmsg.payload = message;\nmsg.topic = topic;\nmsg.device = device;\nmsg.priority = priority;\nmsg.url = url;\nmsg.url_title = url_title\nmsg.attachment = attachmentPath;\nmsg.sound = sound;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":679.9999542236328,"y":86.5000011920929,"wires":[["e6dc791.d3d8608"]]},{"id":"e6dc791.d3d8608","type":"subflow:34d03f0e.2cfc6","z":"df66407a.c32fe","name":"","env":[],"x":922,"y":87,"wires":[]},{"id":"530bb21c.a75b94","type":"comment","z":"bd9f9620.87b7f8","name":"Hubitat Power Outage Management v1.2","info":"","x":233.00001907348633,"y":84.0000228881836,"wires":[]},{"id":"19688c00.414cbc","type":"switch","z":"bd9f9620.87b7f8","name":"Is Harmony BR Up?","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2343.189022064209,"y":203.3333511352539,"wires":[["9fa10d.ecf6eef","25b5267.d6f9a5a"],["8984657.d481b98"]]},{"id":"1a31ddb0.60ee32","type":"ping","z":"bd9f9620.87b7f8","mode":"triggered","name":"Ping Harmony Hub -BR","host":"192.168.1.87","timer":"20","inputs":1,"x":2102.1889839172363,"y":203.33335494995117,"wires":[["19688c00.414cbc"]]},{"id":"9fa10d.ecf6eef","type":"ping","z":"bd9f9620.87b7f8","mode":"triggered","name":"Ping Hubitat Hub","host":"192.168.1.113","timer":"20","inputs":1,"x":2578.1890449523926,"y":98.33334350585938,"wires":[["cc7c64cc.81edd8"]]},{"id":"df548766.b47488","type":"switch","z":"bd9f9620.87b7f8","name":"Is Harmony LR Up?","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1393.1888618469238,"y":484.3333549499512,"wires":[["ee00aa24.9ceab","56ae1d30.59bf34"],["7f30d1fe.a67d"]],"outputLabels":["No","Yes"]},{"id":"cc7c64cc.81edd8","type":"switch","z":"bd9f9620.87b7f8","name":"Is Hubitat Up?","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2775.1890449523926,"y":98.33334350585938,"wires":[["b82fe31a.125d88"],["5ceddc53.dd5eb4"]]},{"id":"85ec547.9b1c728","type":"ping","z":"bd9f9620.87b7f8","protocol":"Automatic","mode":"triggered","name":"Ping Harmony Hub -LR","host":"192.168.1.101","timer":"20","inputs":1,"x":1161.1887702941895,"y":430.3333854675293,"wires":[["df548766.b47488"]]},{"id":"8984657.d481b98","type":"ping","z":"bd9f9620.87b7f8","mode":"triggered","name":"Ping Hubitat Hub","host":"192.168.1.113","timer":"20","inputs":1,"x":2163.1890144348145,"y":510.3335380554199,"wires":[["30a5445e.b302b4"]]},{"id":"1a02458d.8d130a","type":"subflow:df66407a.c32fe","z":"bd9f9620.87b7f8","name":"","env":[],"x":3233.1893310546875,"y":104.33334350585938,"wires":[]},{"id":"2d9fbe21.20cd12","type":"inject","z":"bd9f9620.87b7f8","name":"Monitor Power","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":183.63319778442383,"y":440.5555877685547,"wires":[["cb874255.dc5f6"]]},{"id":"30a5445e.b302b4","type":"switch","z":"bd9f9620.87b7f8","name":"Is Hubitat Up?","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2375.1889839172363,"y":510.3334770202637,"wires":[["b05b1fdd.7746d"],["6744fdb3.87b6b4","ae6df456.5d26d8"]]},{"id":"b05b1fdd.7746d","type":"subflow:bce2c6bb.b4cb4","z":"bd9f9620.87b7f8","name":"","env":[],"x":2567.18896484375,"y":478.33348846435547,"wires":[]},{"id":"2dcaf5f5.f56502","type":"comment","z":"bd9f9620.87b7f8","name":"No","info":"","x":2413.189022064209,"y":165.3333511352539,"wires":[]},{"id":"2e458c6c.a39944","type":"comment","z":"bd9f9620.87b7f8","name":"Yes","info":"","x":2413.189022064209,"y":243.3333511352539,"wires":[]},{"id":"c4b78019.dfaa","type":"comment","z":"bd9f9620.87b7f8","name":"No","info":"","x":2811.439105987549,"y":57.33334732055664,"wires":[]},{"id":"51cee729.a669a8","type":"comment","z":"bd9f9620.87b7f8","name":"Yes","info":"","x":2809.7446479797363,"y":138.4444580078125,"wires":[]},{"id":"822552a2.dfe76","type":"comment","z":"bd9f9620.87b7f8","name":"No","info":"","x":2387.1889839172363,"y":467.5834770202637,"wires":[]},{"id":"7d7bc45e.01e6cc","type":"comment","z":"bd9f9620.87b7f8","name":"Yes","info":"","x":2394.6889839172363,"y":558.8334770202637,"wires":[]},{"id":"ab0f5c12.bdb78","type":"comment","z":"bd9f9620.87b7f8","name":"No","info":"","x":1428.1888313293457,"y":444.3333854675293,"wires":[]},{"id":"5df21e4c.4c6e9","type":"comment","z":"bd9f9620.87b7f8","name":"Yes","info":"","x":1430.188892364502,"y":526.3334159851074,"wires":[]},{"id":"5ceddc53.dd5eb4","type":"gate","z":"bd9f9620.87b7f8","name":"Control Gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":3021.8365478515625,"y":103.30026245117188,"wires":[["36be2078.b236e","1a02458d.8d130a"]]},{"id":"11843359.5d324d","type":"link in","z":"bd9f9620.87b7f8","name":"Set Gate","links":["81b220a1.ec1b9","8ab69250.76a948","a263256d.f6f538","e43fdb66.2e6b18","f7860b3f.f2fcc","dc66b73d.595488","b09ffe5c.c42a5","1dbf9c42.ef7a44"],"x":2909.8399658203125,"y":160.9596176147461,"wires":[["5ceddc53.dd5eb4"]]},{"id":"a3426938.d7a86","type":"function","z":"bd9f9620.87b7f8","name":"Set Notification Params","func":"//Set error message\n\nvar message = msg.deviceName+ \"- not reachable\";\nvar topic = \"Harmony check time - \"+msg.checkDateTime;\nvar priority = 0; //values are -2,-1,0,1,2\nvar device = \"\"; //Blank device = All\nvar url = \"\";  // url to be included in message\nvar url_title = \"\";// title of URL\nvar sound = \"\"; // notifcation sound\nvar attachmentPath = \"\"; //file path if attachment is included\n\n//Inputs for Notification Subflow\nmsg.payload = message;\nmsg.topic = topic;\nmsg.device = device;\nmsg.priority = priority;\nmsg.url = url;\nmsg.url_title = url_title\nmsg.attachment = attachmentPath;\nmsg.sound = sound;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":917.5219612121582,"y":592.0001678466797,"wires":[["a780b775.24a828"]]},{"id":"a780b775.24a828","type":"subflow:34d03f0e.2cfc6","z":"bd9f9620.87b7f8","name":"","env":[],"x":1168.7720832824707,"y":592.0001678466797,"wires":[]},{"id":"e7238158.91b898","type":"moment","z":"bd9f9620.87b7f8","name":"","topic":"","input":"","inputType":"date","inTz":"America/Chicago","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD hh:mm A","locale":"en_US","output":"checkDateTime","outputType":"msg","outTz":"America/Chicago","x":655.5219812393188,"y":592.0001907348633,"wires":[["a3426938.d7a86"]]},{"id":"7ff833de.8a297c","type":"comment","z":"bd9f9620.87b7f8","name":"Change Log","info":"2020-11-02: Moved gate to just before restart process to mitigate conflicts with Hub Mainenance processes\n2021-07-27: Added notifications for Harmony Hubs unreachable - troubleshoot false power outage notifications\n2021-07-27: Updated logic to re-ping Harmony Hub - LR (upto 3 times) if first ping is not successful\n2021-07-28: Change pingCounter to flow variable as msg.pingCounter was being wiped out by Ping node\n2021-07-29: Added GV to stop flow from running concurrently","x":137.52199172973633,"y":696.0000457763672,"wires":[]},{"id":"ee00aa24.9ceab","type":"change","z":"bd9f9620.87b7f8","name":"Device - LR Hub","rules":[{"t":"set","p":"deviceName","pt":"msg","to":"Harmony LR Hub","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1632.522144317627,"y":425.7619438171387,"wires":[["c4102f13.ed8f28"]]},{"id":"c4102f13.ed8f28","type":"link out","z":"bd9f9620.87b7f8","name":"Harmony Notification - Out","links":["82459e55.aa6a1"],"x":1873.5222663879395,"y":426.4285697937012,"wires":[],"l":true},{"id":"82459e55.aa6a1","type":"link in","z":"bd9f9620.87b7f8","name":"Harmony Notification - In","links":["c4102f13.ed8f28","5a08d7e1.ba4f"],"x":399.8553123474121,"y":592.4287452697754,"wires":[["e7238158.91b898"]],"l":true},{"id":"5a08d7e1.ba4f","type":"link out","z":"bd9f9620.87b7f8","name":"Harmony Notification - Out","links":["82459e55.aa6a1"],"x":2875.855609893799,"y":196.09525680541992,"wires":[],"l":true},{"id":"25b5267.d6f9a5a","type":"change","z":"bd9f9620.87b7f8","name":"Set Device Name - BR Hub","rules":[{"t":"set","p":"deviceName","pt":"msg","to":"Harmony BR Hub","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2607.8554725646973,"y":196.42860412597656,"wires":[["5a08d7e1.ba4f"]]},{"id":"37cc5dc0.ca51e2","type":"change","z":"bd9f9620.87b7f8","name":"Set Counter to Zero","rules":[{"t":"set","p":"pingCounter","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":922.0001106262207,"y":429.66669845581055,"wires":[["85ec547.9b1c728","2cba4375.e00e8c"]]},{"id":"7f30d1fe.a67d","type":"switch","z":"bd9f9620.87b7f8","name":"Ping Counter <> 0","property":"pingCounter","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1627.6667976379395,"y":505.33332443237305,"wires":[["548063c8.2d4ebc"],["8984657.d481b98"]]},{"id":"56ae1d30.59bf34","type":"change","z":"bd9f9620.87b7f8","name":"Increment Counter","rules":[{"t":"set","p":"pingCounter","pt":"flow","to":"$flowContext(\"pingCounter\")+1","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1388.0000495910645,"y":309.9999198913574,"wires":[["b4fe14b4.7322c8","8d589800.3e29a8"]]},{"id":"548063c8.2d4ebc","type":"change","z":"bd9f9620.87b7f8","name":"Cancel Delay and Reset Counter","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"pingCounter","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1875.3334846496582,"y":470.66669845581055,"wires":[["e6b5bca5.d6d45","8984657.d481b98"]]},{"id":"e6b5bca5.d6d45","type":"delay","z":"bd9f9620.87b7f8","name":"Delay 1 minute","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1854.0001411437988,"y":315.9999198913574,"wires":[["7c89cfc3.24f2c8"]]},{"id":"b4fe14b4.7322c8","type":"switch","z":"bd9f9620.87b7f8","name":"Counter > 4","property":"pingCounter","propertyType":"flow","rules":[{"t":"eq","v":"4","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1582.33345413208,"y":310.3333549499512,"wires":[["b927aeb2.6fda08"],["e6b5bca5.d6d45"]]},{"id":"b927aeb2.6fda08","type":"change","z":"bd9f9620.87b7f8","name":"Cancel Delay and Reset Counter","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"num"},{"t":"set","p":"pingCounter","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1834.0001411437988,"y":254.66666793823242,"wires":[["e6b5bca5.d6d45","1a31ddb0.60ee32"]]},{"id":"7c89cfc3.24f2c8","type":"link out","z":"bd9f9620.87b7f8","name":"Repeat Ping - Out","links":["629bc8de.d91468"],"x":2063.3335151672363,"y":316.33337020874023,"wires":[],"l":true},{"id":"629bc8de.d91468","type":"link in","z":"bd9f9620.87b7f8","name":"Repeat Ping - In","links":["7c89cfc3.24f2c8"],"x":929.3334465026855,"y":378.66674423217773,"wires":[["85ec547.9b1c728"]],"l":true},{"id":"6744fdb3.87b6b4","type":"debug","z":"bd9f9620.87b7f8","name":"HE up","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2545.000141143799,"y":659.3334426879883,"wires":[]},{"id":"8d589800.3e29a8","type":"debug","z":"bd9f9620.87b7f8","name":"Increment Counter","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1517.0001106262207,"y":237.33337020874023,"wires":[]},{"id":"2cba4375.e00e8c","type":"debug","z":"bd9f9620.87b7f8","name":"Ping Counter","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1094.33345413208,"y":276.6667060852051,"wires":[]},{"id":"df17f198.e6406","type":"change","z":"bd9f9620.87b7f8","name":"Power Management GV = True","rules":[{"t":"set","p":"pmIsRunning","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":653.3333320617676,"y":429.3334197998047,"wires":[["ed9cac7.203ee5"]]},{"id":"cb874255.dc5f6","type":"switch","z":"bd9f9620.87b7f8","name":"Is flow executing?","property":"pmIsrunning","propertyType":"global","rules":[{"t":"false"},{"t":"null"},{"t":"true"}],"checkall":"true","repair":false,"outputs":3,"x":391.3333625793457,"y":441.3334197998047,"wires":[["df17f198.e6406"],["df17f198.e6406"],["bcf90ddd.7ff3c"]]},{"id":"ae6df456.5d26d8","type":"link out","z":"bd9f9620.87b7f8","name":"End PM Flow - Out","links":["c045f872.005c5"],"x":2589.333637237549,"y":542.0000686645508,"wires":[],"l":true},{"id":"36be2078.b236e","type":"link out","z":"bd9f9620.87b7f8","name":"End PM Flow - Out","links":["c045f872.005c5"],"x":3235.6671142578125,"y":155.99999237060547,"wires":[],"l":true},{"id":"b82fe31a.125d88","type":"link out","z":"bd9f9620.87b7f8","name":"End PM Flow - Out","links":["c045f872.005c5"],"x":2995.6667671203613,"y":54.000022888183594,"wires":[],"l":true},{"id":"c045f872.005c5","type":"link in","z":"bd9f9620.87b7f8","name":"End Flow - In","links":["36be2078.b236e","ae6df456.5d26d8","b82fe31a.125d88"],"x":358.3332939147949,"y":645.0000915527344,"wires":[["50e290e3.2e969"]],"l":true},{"id":"50e290e3.2e969","type":"change","z":"bd9f9620.87b7f8","name":"Power Management GV = False","rules":[{"t":"set","p":"pmIsRunning","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":608.6666603088379,"y":646.0000534057617,"wires":[["7a3f5d6c.90144c"]]},{"id":"7a3f5d6c.90144c","type":"debug","z":"bd9f9620.87b7f8","name":"End Flow","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":854.6667060852051,"y":646.6667098999023,"wires":[]},{"id":"bcf90ddd.7ff3c","type":"debug","z":"bd9f9620.87b7f8","name":"PM Running True","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":611.3333435058594,"y":505.00003814697266,"wires":[]},{"id":"ed9cac7.203ee5","type":"delay","z":"bd9f9620.87b7f8","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":773.3333435058594,"y":330.00000762939453,"wires":[["37cc5dc0.ca51e2"]]}]

When you click it the first time does it run through and come out at the End Flow debug?

Add Debug nodes to all the outputs of the Switch node at the front and see where the messages go. Give the debug nodes names so you can see which is which.

Just noticed you have spelt the global wrong in the Switch, you have pmisrunning instead of pmisRunning

1 Like

Yes it does. I did one test with single inject click and then I did it twice in a row, In the second case, I expected the output to come from the PM Running debug (since the GV is set to true after the first click), but it never did. What I got were 2 outputs from the End Flow debug with 2 different payload values (representing the ping times), hence I was thinking that the the flows were not running concurrently.

I had done that in a previous iteration. I changed the IP for the ping nodes to be invalid values and the output was going down the correct paths. This final test was to see what would happen if the the same flow was triggered twice (before the first one finished).

If you remove the two sub flows (and put in some valid IP addresses in the ping nodes), you should be able to trigger the flows and see the output. All the non-standard nodes are in the sub flows (I think).

Did you see my last post? I think it crossed with yours.

1 Like

AARGH - I thought I'd checked that all the way :man_facepalming:t3:

Just fixed that and now the output is directed correctly (to the PM Running True debug node). So I guess I will keep the flow the way it is (with the global variable to prevent concurrent execution). Thanks a lot for your help!

Personally I think I would use a node-red-contrib-simple-gate to block or allow the inject message through, rather than using the context. I don't like using context in that way as it effectively adds invisible connections between nodes.

I was trying to wrap my head around the gate node but I was having a hard time thinking through it with the various branches. I will take another look at it though and see if I can figure it out. Thanks!

Something like this should do it

[{"id":"8e3ad038e9ffb525","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":1380,"wires":[["fc88942e777b328d"]]},{"id":"fc88942e777b328d","type":"gate","z":"84405ff5.25fa6","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memoryOnly","x":390,"y":1380,"wires":[["e6ac6c78532d2201","7025848d6f17d12e"]]},{"id":"e6ac6c78532d2201","type":"link out","z":"84405ff5.25fa6","name":"Close","links":["e41c155db566f269"],"x":495,"y":1460,"wires":[]},{"id":"e41c155db566f269","type":"link in","z":"84405ff5.25fa6","name":"","links":["e6ac6c78532d2201"],"x":175,"y":1520,"wires":[["31c98bdea4b3ddab"]]},{"id":"31c98bdea4b3ddab","type":"change","z":"84405ff5.25fa6","name":"Close","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1520,"wires":[["fc88942e777b328d"]]},{"id":"7025848d6f17d12e","type":"delay","z":"84405ff5.25fa6","name":"Do something","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":600,"y":1380,"wires":[["c2090fbbc1afbbc9","17898aa51f0a5ef7"]]},{"id":"c2090fbbc1afbbc9","type":"debug","z":"84405ff5.25fa6","name":"DONE","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":1380,"wires":[]},{"id":"17898aa51f0a5ef7","type":"link out","z":"84405ff5.25fa6","name":"","links":["7c8981315c0ca8d8"],"x":735,"y":1480,"wires":[]},{"id":"7c8981315c0ca8d8","type":"link in","z":"84405ff5.25fa6","name":"","links":["17898aa51f0a5ef7"],"x":175,"y":1600,"wires":[["41524dcfc0d0dd14"]]},{"id":"41524dcfc0d0dd14","type":"change","z":"84405ff5.25fa6","name":"Open","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1600,"wires":[["fc88942e777b328d"]]}]
1 Like

Thanks - I did something almost the same (wish I had seen this before)!!

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