ML Logic question

I am using modes to manage some lights and was having some issues when user activity did not match up with the timing of mode changes. So I added some motion sensors and am trying to work out the logic now.

I have 2 lights that I want to turn off when the mode switches to 'Home - 6 Night' unless there is motion in which case I want it to delay for 20 min of no motion and then turn off. That seems to be working with this ML rule where I have it disabled on my other home modes.

My logic question is what happens if motion was to end 21 min before the mode changed to 'Home - 6 Night'? Would the lights stay on until another motion active and 20 min delay (I think this would be the case) or would they turn off because it has been past the 20 min delay and the mode is no longer disabling the action?

Your assumption is correct--the lights will not turn off. What I don't know (and this made me think of--suppose it had only been 19 minutes) is whether the mode matters at the time the "motion active" event fires or at the time when the specified (20 minutes, here) delay is up. That is certainly testable, and perhaps someone who has (or Bruce) could tell us. But I do know it won't care about long-gone timers after a mode change in the way you posit.

That is what I was afraid of. Ideas on how to work around that issue?

I can answer your I don't know as I tested that last night. Motion ended at 9:45 and the 20 min delay started. Mode changed at 10 and at 10:05 the lights turned off.

Maybe make a rule triggered by motion active, a wait for event - motion inactive, a wait for event - elapsed time for 20 minutes, then a check to see if mode is whatever and turn it off if so? (This will be a bit less awkward in the next firmware version based on a new Rule feature they've publicly announced, time since a last specific event, but it's still do-able now like this.)

That sounds like it is still based off of motion happening within 20 min of the mode change or that final check of the mode would still prevent the off.

Does this basic rule look to cover both situations?

Ah, yeah, I pretty much re-created the exact situation you didn't want...didn't think that through haha. So, waiting until the next release might give you an easy way to get what you want, otherwise maybe you can make this simpler in the meantime by creating a boolean hub variable, setting its value to true or false when motion has remained inactive for so long, then checking that value on mode change (or any time it changes and then checking mode, depending on what you want)--in a separate rule.

Your Basic Rule will work if you want motion to turn off as soon(-ish) as the mode change happens, but it won't wait for the sensor to become inactive. So, you may be in for a surprise if you're moving around when the mode happens to change.

This rule seems to be working perfectly. After the mode changes as long as there is motion for the time set then the lights stay on. We did have one time when there was no motion before the trigger and the lights were off as expected but I did not check the logs in time to validate. So as of now, this is working how I wanted.

With the new release, what is the easy method now?

The basic rule is working as long as there is motion after the mode switch. If there is no motion triggers after the mode switch then the lights stay on.

1 Like

Download the Hubitat app