Apparent change of value of local variable during execution of a rule 5.1 rule

I am running a Rule 5.1 rule that monitors the opening and closing of Abode door and window contacts. When a contact is opened an announcement is made to Echo devices and the contact name is stored in or added to a global variable. When a contact is closed the contact name is removed from the global variable.

The rule is triggered on Abode timeline entries - like below:



Sometimes the Abode timeline event occurs but the event does not trigger the execution of the rule. I believe I saw a post about custom triggers not always working in release 2.3.5.117 so I hope that will be fixed.

Also it appears that a local variable changes to a prior value during the execution of the rule. In the log below the local variable State appears to revert to a prior value - lines in green and italic text highlights the change.

My guess is the wait is messing you up. If you want to use %device% and %text%, etc. You want to capture the value before any other waits, as a wait will change them.

1 Like

Thanks for the quick reply. The wait on global variable named Abode Serialize Lock was my attempt to single thread the rule and try and prevent this issue that was occuring before I added the wait .

Additionally the log shows that local variable named State is the variable that seems to have incorrectly changed. It was originally set to Front Lock South Closed which is the correct value for the event. A few instructions later the text Front Lock South is replaced with an empty variable into State which should have resulted in the value Closed but in fact resulted in Open.

The prior execution of this rule would have initialized the variable State to be Front Lock South Open from the prior Open event.

This issue does not always occur but does occur frequently enough as to make the rule unusable.

Does anyone know I should direct this issue to Hubitat Support instead of just the user community

@terminal3 correctly assessed your issue. The Wait is going to change the value of %text%. So, grab that value before the Wait.

@bravenel - thanks for the reply. Even in my first example the State variable was already correctly captured and then appeared to change. Subsequently I moved the following statements to before any wait and to the top of the rule:
Set State to '%text%(Garage South Closed)'
Set Contact to '%text%(Garage South Closed)'
and the issue persisted.
I subsequently removed the wait statement as that was an attempto to serialize/single thread the rule.
It appears to me that the problem occurs when a second coy of the rule triggers and runs while (or very shortly after) a prior copy of the rule is still executing (or has recently executed).
Is there a correct way of single threading a rule so that only one copy of it can run at a time. Waiting on a variable that is set at the beginning of the rule and reset at the end of the rule does not really work since the variable manipulation is inside the rule and there is a timing exposure than can still allow concurrent execution of the same rule.
Thanks, Russell.

Use a Required Expression, where the expression is Private Boolean is True. Then first action of rule sets Private Boolean to False, and last action sets it to True again.

1 Like

@bravenel Thanks for this solution. I had not previously used Required Expression and wasn't fully aware of when to use Private Boolean

I have added the following Required Expression to my rule
image

It appears that Private Boolean is false when the rule is not running so I used the reverse of your example. This rule gets triggered several times a day so I should know in a few days if the issue is resolved.

Thanks again for you help.

Private Boolean starts out true when a rule is first created. But, after that, it has whatever value it has. It can be set on the Actions page Local Variable table by clicking on its value.

The "rule running" is not relevant to the value of Private Boolean.

@bravenel. Oh, I misunderstood. I will make the change in my rule to explicitly set the Private Boolean value.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.