Preventing multiple simultaneous instances of a rule

What the topic says.

I have a rule that is essentially a "countdown timer" and I have it set to run anytime a variable value is >0. Essentially, many different things can add +1 to the value of that variable, which is kept at a max value of 3.

At first I tried a simple repeating rule, that said:

  • [repeat every 30 seconds while expression variable >0 is true]
  • [wait for event:29 seconds]
  • [add -1 to variable]
  • [end rep]

The problem is that multiple different things contribute to adding to the variable value, prompting a new instance of the counter to start every time. I would prefer if once the timer is started, it just keeps going until the variable =0, and not start a new instance everytime the variable is "topped off".

My first workaround was to simply remove the repeat and put a simple trigger:

  • [variable reports value between 1-3]
    with a much simpler action:
  • [wait 30 seconds, then add -1 to variable value]

This has resulted in much less load on the hub than stacks of repeating rules. However, does still have it's own problems, as there is still a new instance of the rule launching all the time when there is activity adding to that variable value. This prompted me to create another rule to prevent extra instances from decreasing the value to negative values by having a [end rule timers] action when variable =0.

It seems like going back to the simple repeating action would be ideal as long as I could ensure it only runs one instance. Any ideas?

How do I do this?

Thanks I will give this a shot.

1 Like

Well I just learned a new trick. Thanks for that! For whatever reason, in like 5 years of having Hubitat, I never bothered to learn how to utilize the Private Boolean function. I think this is actually going to prompt a re-write of several other rules now.


You can use it for interlocking distinct rules, too, as a rule can set the private Boolean of another rule.


Yes, this exact thing prompted me to realize I could simplify a lot of logic that I had implemented to do things that private boolean could do easier. Lots of virtual state switches can probably be removed now.