RM - Executing an action based on sequential events

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.

Something like:

If front door sensor open then
wait X seconds
if front door motion then action
end

Wouldn't that do the trick?

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 do and just added a section to the docs clarifying this last night. :smiley: Rule 5.1 | Hubitat Documentation

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.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.