Make sure the flow only runs once at the same time

Let’s say we have something like this:

[
   {
      "id":"4cc8580d.e4c528",
      "type":"tab",
      "label":"Flow 2",
      "disabled":false,
      "info":""
   },
   {
      "id":"553aeb15.6cc8b4",
      "type":"trigger-state",
      "z":"4cc8580d.e4c528",
      "name":"",
      "server":"4bbca37b.1700ec",
      "exposeToHomeAssistant":false,
      "haConfig":[
         {
            "property":"name",
            "value":""
         },
         {
            "property":"icon",
            "value":""
         }
      ],
      "entityid":"light.sonoff_1000a2f786",
      "entityidfiltertype":"exact",
      "debugenabled":false,
      "constraints":[
         {
            "id":"qrda6lya809",
            "targetType":"this_entity",
            "targetValue":"",
            "propertyType":"current_state",
            "propertyValue":"new_state.state",
            "comparatorType":"is",
            "comparatorValueDatatype":"str",
            "comparatorValue":"on"
         }
      ],
      "constraintsmustmatch":"all",
      "outputs":2,
      "customoutputs":[

      ],
      "outputinitially":false,
      "state_type":"str",
      "x":190,
      "y":120,
      "wires":[
         [
            "1a6d6956.8a2457"
         ],
         [
            "1a6d6956.8a2457"
         ]
      ]
   },
   {
      "id":"1a6d6956.8a2457",
      "type":"delay",
      "z":"4cc8580d.e4c528",
      "name":"",
      "pauseType":"delay",
      "timeout":"2",
      "timeoutUnits":"seconds",
      "rate":"1",
      "nbRateUnits":"1",
      "rateUnits":"second",
      "randomFirst":"1",
      "randomLast":"5",
      "randomUnits":"seconds",
      "drop":false,
      "x":440,
      "y":140,
      "wires":[
         [
            "68c61b29.e1f914"
         ]
      ]
   },
   {
      "id":"68c61b29.e1f914",
      "type":"api-call-service",
      "z":"4cc8580d.e4c528",
      "name":"",
      "server":"4bbca37b.1700ec",
      "version":1,
      "debugenabled":false,
      "service_domain":"light",
      "service":"turn_off",
      "entityId":"light.sonoff_1000a2f786",
      "data":"",
      "dataType":"json",
      "mergecontext":"",
      "output_location":"",
      "output_location_type":"none",
      "mustacheAltTags":false,
      "x":610,
      "y":140,
      "wires":[
         [
            "4f67dc9c.8b2f54"
         ]
      ]
   },
   {
      "id":"4f67dc9c.8b2f54",
      "type":"delay",
      "z":"4cc8580d.e4c528",
      "name":"",
      "pauseType":"delay",
      "timeout":"2",
      "timeoutUnits":"seconds",
      "rate":"1",
      "nbRateUnits":"1",
      "rateUnits":"second",
      "randomFirst":"1",
      "randomLast":"5",
      "randomUnits":"seconds",
      "drop":false,
      "x":780,
      "y":140,
      "wires":[
         [
            "f338f501.4e65d8"
         ]
      ]
   },
   {
      "id":"f338f501.4e65d8",
      "type":"api-call-service",
      "z":"4cc8580d.e4c528",
      "name":"",
      "server":"4bbca37b.1700ec",
      "version":1,
      "debugenabled":false,
      "service_domain":"light",
      "service":"turn_on",
      "entityId":"light.sonoff_1000a2f786",
      "data":"",
      "dataType":"json",
      "mergecontext":"",
      "output_location":"",
      "output_location_type":"none",
      "mustacheAltTags":false,
      "x":950,
      "y":140,
      "wires":[
         [

         ]
      ]
   },
   {
      "id":"70c8d0c3.ce3e",
      "type":"inject",
      "z":"4cc8580d.e4c528",
      "name":"",
      "topic":"",
      "payload":"",
      "payloadType":"date",
      "repeat":"",
      "crontab":"",
      "once":false,
      "onceDelay":0.1,
      "x":260,
      "y":180,
      "wires":[
         [
            "1a6d6956.8a2457"
         ]
      ]
   },
   {
      "id":"4bbca37b.1700ec",
      "type":"server",
      "z":"",
      "name":"Home Assistant",
      "addon":true
   }
]

So it’s triggered on the light state change, and in the flow it changes the state.
This becomes a never ending flickering of the light on and off. The only way out is to deploy a new flow without the connection to the service calls.

But what would be the method to have this kind of setup but limit the flow to only run once at the same time?
Meaning it will do the flow and not repeat itself. But the next time I flick the switch one minute later it will do the flow again.
So it can run several times a day but not more than once at the same time.

Limit node?

I can’t find a node called limit.

The name is as follows:

I will look at it tomorrow but by the looks of it that won’t work.
I need to have a flexible time of when to drop messages.
It could be seconds or it could be hours.
The time is not really relevant, it’s that there is no backlog of messages in the pipe that matters.

You should use a different entity in the trigger node, maybe a switch.

[{"id":"1cf386dc.b6fc09","type":"trigger-state","z":"f0946d4a.679be","name":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"light.sonoff_1000a2f786","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":278,"y":272,"wires":[["d9cebc4.e94fd4","ebcd79fd.03c1a8"],[]]},{"id":"d9cebc4.e94fd4","type":"delay","z":"f0946d4a.679be","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":528,"y":276,"wires":[["326dd246.d301fe"]]},{"id":"326dd246.d301fe","type":"api-call-service","z":"f0946d4a.679be","name":"","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.sonoff_1000a2f786","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":698,"y":276,"wires":[["da2801cb.d8277"]]},{"id":"da2801cb.d8277","type":"delay","z":"f0946d4a.679be","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":868,"y":276,"wires":[["2d8a518c.7261ce"]]},{"id":"2d8a518c.7261ce","type":"api-call-service","z":"f0946d4a.679be","name":"","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.sonoff_1000a2f786","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1038,"y":276,"wires":[["9d5f3215.e2e4"]]},{"id":"bd759695.f20478","type":"inject","z":"f0946d4a.679be","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":348,"y":316,"wires":[["d9cebc4.e94fd4"]]},{"id":"ebcd79fd.03c1a8","type":"change","z":"f0946d4a.679be","name":"disable","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":524,"y":224,"wires":[["1cf386dc.b6fc09"]]},{"id":"9d5f3215.e2e4","type":"change","z":"f0946d4a.679be","name":"enable","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1202,"y":272,"wires":[["1cf386dc.b6fc09"]]}]
1 Like

I like this, as it breaks the 2 troublesome loops in a simple way that also prevents weird behavior if you had 2 external state changes in under 4sec (the ‘origin node’ is disabled then reset after the flow finishes).

This works if you add a 2 second delay before the enable.
If you don’t delay between it sees the light on at the same time as enable hits the trigger so it repeats itself.

Thank you!

It’s probably a better practice to use a wait-until node. That way you will know that the light status changed to on before enabling the trigger node. The same could be said about the delay between off and on unless the 2 seconds is what is wanted.

True!
But this is just a simplified version of what it’s supposed to be.
But definitely a wait until. Thank you!

Put a Trigger-block before the first delay and then use a Change-block after the turn_on and connect the Change-blocks output to the Trigger-block input.

The Change-block sets the property msg.reset and the Trigger-block is reseted when it receives that property.

This should prevent a new cycle until the last is completely finished.