Exit rule run before earlier commands are done

Hi to all,

I have a rule that repeats every 10 seconds as long as required. To check if it is still required it checks a hub variable set by some other rules. If the variable has not the correct value, the rule stops all timed actions and exits itself. That works apparently fine.

To assure that the rule does nor run twice I check private boolean at the beginning and set it to false.

IF (Private Boolean(true) is false(F) [FALSE]) THEN
	Exit Rule
Set Private Boolean(true) False

The exit condition sets the private boolean to true again before exiting.

IF (Variable vDynamicSceneTVlamp(0) != 1(T) [TRUE]) THEN
    Cancel Timed Actions: **This Rule**
    Set Private Boolean(true) True
    Log: 'Moonrise : Check for stop was run'
    Exit Rule

The above code runs now fine, but the first versions did not have the Log: command and the private boolean was never set to true. I suppose that the exit happened before that the command had internally be executed and adding the log command gives some extra time, but that is just my guess.

Is this behaviour normal, or is it a bug ?

Looking at the first rule, there is nothing in the rule that would set it to true. I only see a command to set it to false.

There is no need to have an Exit Rule command unless there are other commands after the if condition that you don’t want to run. And even then, in your first rule, you could just invert the If condition to check if the boolean is false, then where you have your “Exit Rule”, command, have a command to set it to true instead.

1 Like

As far as I understand this is the standard way to use private booleans and it works very well in other rules that I have (without an exit command).

The private boolean is by default true for every rule. The first time this rule is run it passes the check and sets the private boolean to false. Any try to run the rule again and to create a second instance of the rule that runs in parallel to the first on, exits this second instance as the private boolean is false.

By exiting my first instance I have to set private boolean to true again, to be able to run the rule again later.

This is kind of complicated and I would really like Hubitat to give us an easy way to check if an instance is already running by handling this internally like "IF (Instance running(true) = false) THEN

True, this is inside a rule that loop permanently every 10 seconds as it is a dynamic light scene that acts differently depending on the scene, the scene stage and on differently on different bulbs. The scene stage changes depending on the archived light color or intensity of one or another bulb...

Really nice when it works but I struggled with many problems like bulbs switching on again after the light (all bulbs in a group) has been switched off as the timed actions did not correctly stop and so on...

For the rule look here: [Dynamic light scene - Is my rule OK or is there an easier way to do it?]

1 Like

That would be nice, though the use of a boolean has been the recommended approach, so what you are doing is the right approach. I’ll take a look at your “real” rule.

Actually, now that predicates are available. I believe that’s a much clearer way to do this. First, it’s clearer and takes the IF test out (just have a predicate of Private Boolean = True). Second, if the Predicate is false, that shows up on the Apps page.

So it is clearer, and solves the status-indicating issue.

1 Like

Yes, absolutely. But the use of a 'private boolean' is not really intuitive. An 'Instance running' or even better 'Instance already running' would be much clearer.