Mode saved to a variable, most of the time correctly?

I have a rule that is triggered by the location mode change. I then store the mode in a variable

so that I can pass the variable to Pushover in a string to make up part of an alert. Most of the time it works fine. Occasionally, I get the wrong mode being sent to my alert. Here is a screenshot of the log.

The first two events worked correctly. The third one at 16:56:31 did not. The mode changed to Away, but the word Home was stored in the variable.

Why? Is this a timing issue? It shouldn’t be, because the mode change has already occurred otherwise my rule would not get triggered.

Likely, yes. If the rule is using the mode as the trigger, then you should use the Context Variable → Event Value for setting the variable.

I made the change as you recommended. However, I’d like to understand why this is different. If your system sets the context variable’s value because of the trigger, how is that any different than me grabbing the value of the mode which has just changed.

I was originally just going to put a 1 second delay before getting the value, to hopefully eliminate a timing issue.