I have a rule that turns off a virtual switch early in the rule and then later uses that state in a condition. As you can see from the timing sequence, the switch is turned off (image 1, also in the switch events itself in image 2), but then the condition later in the rule acts as if it’s not off (image 3). Is it that:
A condition in a rule takes the state of devices at the time that the rule initially runs and it’s acting on that state? (I don’t think this is the case because I believe I do this in other places and it works)
Although the actions are sequential per the time stamps, they are happening too quickly as to not allow the status of the switch device to update? (I have added a delay to test this.)
With barely 700 ms between the two actions, it's possible the event has not fully "committed" yet. For a real device, this would likely not be quite enough time for the switch to receive the command, send a report back, and for the driver to then parse it into an event; with a virtual switch, that would probably only be milliseconds (and probably not that many). But that could still be what you're running into.
The two ways I see around this are:
Insert a safe but possibly still small delay before the check; or
Consider some other way to work your rule logic (e.g., if you just turned off a virtual device, you would not normally need to immediately check if it is off--it should be).
The second option is normally cleaner and would be my preference, but it's hard to say more without seeing the actual rule.
Thanks. I added the delay so I will check when it runs again tomorrow morning. #2 isn’t an option in this case, because I only want the actions governed by the latter condition to run if the switch is off, and the switch is part of another condition, and does not turn off in all situations by design.