RM 5.1 Local Variable in Required Expression

@bravenel I think I've found a bug in Required Expression.

Here's the test rule, which attempts to use the local variable "RuleRunning" to stop the rule from running more than once at a time:

Screenshot 2022-01-07 at 12-42-29 test

"test switch" is a Virtual Switch, with a 1 second auto-off. Here's the log when it's turned on twice, once at 12:44:40, the second time at 12:44:44 (3 seconds later):

Screenshot 2022-01-07 at 12-45-09 Logs

As you can see, the Required Expression is ignored, and the rule runs twice simultaneously.

I tried the same thing recently with the same results. For some reason a local variable would not work, but using the private Boolean did.

I would have preferred to use a local Boolean because, as in your example, the logic made more sense, True the rule is running, false it is not. Since a private Boolean starts out true I had to use opposite logic.

I have shied away from using Private Booleans in general, just because I find them harder to debug. Viewing a Rule from its main screen, you can see the values of local vairables, but there's no way (outside of another rule) to query the value of a PB.

Local variables won't work for this purpose. Hub variables would, as does Private Boolean (treated as special case). A local variable cannot be 'subscribed' to, so it changing value does not cause the re-evaluation of the Required Expression. While it would be possible to disallow local variables in Required Expressions, they can be used for other purposes successfully, just not for the primary purpose of triggering re-evaluation.

3 Likes

Gotcha, Bruce - thanks for the clarification.

See clarification above about using Private Boolean for this.

This is not correct. You can see the value of PB right in the rule:

2 Likes

Download the Hubitat app