Preventing rule from being triggered again whilst running

I am trying to do a simple thing .. when a PIR triggers, save the current dimmer value and increase the dimmer to 100. After a delay revert to the original dimmer value. I have this code ..

Capture: Study Downlights
Dim: Study Downlights: 100 --> fade: 0
On: Study Downlights
Delay 0:00:20
Restore: Study Downlights

Which works fine unless the PIR triggers again during the delay. In this case the rule runs again and the Capture value is 100, Consequently the original dimmer value is lost and the lights never return to the original value.

What I need is a way to stop the rule running again until it has completed the first time (and therefore restored the original value in the dimmer).

Your help is greatly appreciated, thank you.

Use a required expression that tests if a Private Boolean is true to trigger the rule.

Then make the first action to set the rule’s PB to be false, and the last action to make the PB true again.

2 Likes

Thank you for your reply. If I use Private Boolean how do I ensure it is set true initially? If it was false when the RM started the rule would never be triggered?

Also, should the Private Boolean test be in the trigger condition or a conditional at the beginning of the Actions?

Thanks again for your help, I have never visited a forum with such helpful and polite comments.

1 Like

PB always start out as being true (when first created). And in your rule, your actions would be something like:

Set Private Boolean False
Capture: Study Downlights
Dim: Study Downlights: 100 --> fade: 0
On: Study Downlights
Delay 0:00:20
Restore: Study Downlights
Set Private Boolean True

So when the rule is done running, the PB is True again for the next time the rule is triggered.

This. Doing so prevents the rule from being triggered when the PB is False.

The only circumstance that will leave the PB in a False state is if your hub was rebooted or froze while the rule was still being run. To circumvent this, create a second rule that sets the PB for this rule to be true when the hub is restarted. The trigger for a restart is the location event "SystemStart".

1 Like

Great thank you. I can add the rule to set PB true on restart and it should all be OK. Thanks for your help.

1 Like

In the rule's Local Variable table, clicking on the Private Boolean value will toggle between true/false.

1 Like

??

Not sure what the relevance is to Rule Machine.

2 Likes

Can PB' also be used to cancel an action?

I have a routine like this:

Triggered by: button press
30 sec delay
Do stuff

If that button is pressed by accident, I'd like to press it again during the delay to cancel it. Can PB's be used to accomplish this?