Rule machine, help with cancellable actions

Hi,
Starting with hubitat and rule machine and I am struggling with defining this rule to work as I want to. My intention is that a PIR in my masterbed is triggered and turns on the light for 5mins if my wife is not sleeping and the light level is dim and if there is further motion detected to extend the 5mins, and turn off the lamp after 5mins of no motion.

I have it correctly triggering as I would expect, but the light is never turning off, how do I define the 5min rule so it cancels if no motion detected and not turn off if I am still in the room?
thanks.

The "cancelable" flag that you (correctly) set on the delay doesn't do anything unless you have a "Cancel Delayed Actions" action somewhere in your actions--that's what actually cancels it (and everything after it, assuming you have the dedicated "Delay" action as you do here). In general, that may help you. But for this rule in particular, the layout seems a bit odd. If you're trying to wait until motion is inactive before starting the 5-minute countdown, nothing is doing that: your rule only triggers based on motion being active, and only triggers will make your actions run (with rare exception--e.g., unless you call them from another rule). Two general structures that would work for that are:

Option 1:

Trigger events: Motion *changed*

Actions:

IF (Motion active) THEN
  Cancel Delayed Actions
  On: Lights
ELSE
  Delay 0:05:00 (cancelable)
  Off: Lights
END-IF

or

Option 2:

Trigger events: Motion active

Actions:

Cancel Delayed Actions
On: Lights
Wait for event: Motion inactive
Delay 0:05:00 (cancelable)
Off: Lights

Either will have the exact same outcome in this case--just two different ways of writing the logic to get there. You'll see a lot of the former in the Rule 4.0 documentation, which I recommend reading if you haven't (as I'm guessing you maybe haven't based on the fact that it contains a nearly identical example :slightly_smiling_face:). The latter is a paradigm staff began suggesting a while back, as it may be simpler.

Since you have more conditions to worry about than just the state of the motion sensor, you may find one easier than the other to work with as a starting point, adding in your additional logic. It seems like either should be easily adaptable to your specific case. This is the general structure you want regardless. Good luck!

1 Like

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