Rule Engine: State Stays Variable Improvements

Today’s release includes improvements with how the State Stays feature in the Rule Engine works with Variables.

With this update, State Stays triggers for Variables only use the initial state change for determining if a variable state has stayed the same.

Improvement: Prevent Recurring Triggers

Previously, if a variable was updated with the same value, it would trigger the State Stays condition for every update. For example, if a variable was initially changed from false to true and then subsequently set to true again, the State Stays trigger would fire for every subsequent true update.

To work around this, you previously needed to use an IF Condition to determine if the target variable should be updated. Something like IF $isOn is not true, then set $isOn = true. With the release of this enhancement, you no longer have to avoid updating the variable with the same value to prevent State Stays Triggers firing again with subsequent updates.

:stop_sign: That also means that if you intentionally want to cause a State Stays trigger to fire again, the variable must first change state. (eg. change to false and then back to true)

This does not impact normal equality / comparison checks as an event is still fired each time a variable is updated. This only impacts ‘state stays’ triggers.

Bug Fix: Unexpected Triggers

Perhaps more importantly, this resolves a bug where State Stays triggers could incorrectly fire in certain scenarios. If the State Stays trigger entered ‘pending validation’ and within the state stays duration it changed to a different value twice in a row (eg. the same ‘other’ value twice), it would incorrectly get treated as having stayed the same value even though it had changed from the original value.

For example, let imagine you had a Trigger based on a variable staying true for a period of time. If that variable changed to true it would enter the pending validation state as the rule waited to see if the value stayed the same for your desired duration. If the variable was quickly changed to false twice or more before the State Stays period expired, the Trigger would incorrectly fire when it shouldn’t have.

2 Likes

Is this the reason my rule to change my away state stopped working?

I have a simple rule where I tap and, if “present” was active for 2 seconds, it would change to “away” a d vice versa. Now it doesn’t trigger any “if active for 2 seconds” anymore.

Can you PM me the Rule ID so I can take a closer look?

Edit: I was able to reproduce and I’m looking into it.

1 Like

@Sgt.Flippy_PJ we just pushed an updated to address this. Can you try again?

1 Like

Yup, it works again!

1 Like