Trying to get this rule going on 184.108.40.206 Rules Machine. I have a virtual presence sensor and a virtual button. I'd like the Virtual Presence to toggle between present and not present every time the virtual button is pushed.
It seem to be working to go from not_present to present (arrived) but not the opposite (departed). Any idea why? Probably something dumb I am overlooking.
That should work. What do the logs say when you press the button? (I can't tell if you have "Action" logging enabled from the screenshot, but that would be the most helpful here--though all logging is also good.) Also, does the virtual presence device work when you manually run the
departed() commands? (If not, the rule--or anything else--won't be able to do it, either.)
the VP sensor works when activated manually.
Here is what I see (newer is on top). The first toggle (to present from not present) works but the toggle from to not present doesn't.
The second from top line in the logs tells you why: both conditions apparently evaluated to true at that moment. So, both actions are actually getting run, but the result of the last one is effectively what sticks because of the changes both make.
If you pressed the button very fast in quick succession, I could maybe see this happening then (event gets committed just as you happen to be in between these actions). If not, I not sure what to suggest; it's possible there's a bug here (not sure I've seen any others reports) and it might work if you re-create the simple conditional or redo the whole last part as a "full" (IF expression THEN...ELSE...END-IF) conditional instead, though logically that should be the same.
@bertabcd1234 that worked, by using the full condition, thank you. not sure what was wrong with the previous approach though obviously now, it wasn't the right one or simpler.
Oh no, there wasn't anything wrong with what you did--it should have worked. It appears RM just had problems evaluating one of the conditionals in one of the cases. (Might have worked if you re-created the condition or rule, but it's not clear to me my it failed.)
Glad you got it working, in any case!
On some of my rules where I found I had conditions like this, I created two rules each with a different "Predicate Rule". One Predicate Rule would say run only if Presence was currently set true. The other rule would say run only if Presence was currently set to False.
Another idea, would be to add a delay before the if statements of say, 1 second. Something like:
Log: ___ Presence Toggle Button pushed
Delay: 1 Second (Stoppable) <-- Stops possible race condition before evaluating if statements
If (___- Presences present True)
departed () on ...
Else-If ( ... present False)