Is it possible using RM to run an action only when the first event fired before the second? Example, If I leave out my front door, the first event is that the contact has opened. The second event is the motion sensor is triggered.
I was hoping this might be done using variables where I compare device since time. Pseudo example:
if (contact open since time > motion active since time) then ...
But I can't get the right data into the variables that I need to compare. Any help is appreciated.
Yes, something like this would be the general pattern for that:
Trigger event:Motion active
Actions to run:
Wait for event: Motion active
// Whatever else
But...you likely care about time between, so you'll have to add something else. You can do that by using the "timeout" option on the "Wait for event" and then using a local variable plus the built-in device variable (which gets set to the name of the triggering device or, crucial here, "timeout" if a Wait timeout expires). That would look like:
Trigger event: Motion active
Actions to run:
Wait for event: Motion active --> timeout: 0:00:30
Set myStringVariable to '%device%'
IF (NOT myStringVariable = 'timeout') THEN
// do things
END-IF
Thank you, I knew there had to be a pattern that I wasn't aware of already created. I'll give this a try and see if I can get things to work as I expect.
Do you know what the key differences are between Wait for event vs Wait for expression? Should I use one over the other?
I prefer "Wait for expression" unless I have a need to test the state (condition) at that time. That's the difference: "event" needs an event to actually happen at some point after that action is reached and does not care about the current state.
The way I usually do it is have a boolean variable like contact_opened, then when the contact opens I would set that to true, and at the same time set it back to false with a delay of however long.