Trigger on condition with duration

Is there a way to configure a trigger such as this:
Trigger:
IF Contact sensor is open is true FOR 5 min
Action
Then Send message

I am having trouble with the "FOR 5 min" Part. Any help is appreciated.

You can't do this with a trigger; triggers are pretty simple and just cause your "Actions" to run when any event happens that matches any trigger. But you can still do what you want--you just have to do it in the actions instead.

To get what you want above, try something like this instead:

Trigger: Contact sensor opens

Actions:

Wait for event: contact sensor closes --> timeout 0:05:00
IF (Contact sensor open) THEN
  Send message, etc.
END-IF

The idea here is that after triggering based on the contact sensor opening, the rule waits for either the sensor to close or 5 minutes to pass. The IF checks why we got to that point in the rule: if it's because the 5 minutes passed, then that IF will evaluate to true because the sensor will still be open, so the actions inside the IF THEN ... END-IF will run. If we got there because the sensor closed (per the "Wait for event"), then this test will fail and your rule actions will effectively be done executing. Finally, we do not need to worry about "resetting" the timer in this case because any trigger that matches will cancel any in-progress "Wait" events (and subsequent actions), so closing and re-opening the sensor will start everything over.

Hope this helps!

2 Likes

Simply for variety, here is my rule to reset the Litter-Robot gauge on Dominic Meglioā€™s (@dman2306ā€™s) port of the Litter Robot driver if the litter drawer is open for at least 30 seconds, as happens when you change the litter bag. Lets you peek without causing a reset. Thereā€™s some other stuff in this simple rule, but I provide it to show you can do this by measuring elapsed time. ā€œLitter Robot Drawerā€ is a contact sensor on the drawer.

Litter Robot Drawer Open/Close Monitor

1 Like