I made the mistake of jumping right into Rule Machine instead of Basic Rules. I need Rule Machine to accomplish a few things. However, it seems to lack some items Basic Rules has.
The one I notice so far that's leaving me puzzled is that Rule Machine lacks any setting for motion sensors similar to the one in Basic Rules "Motion has Stopped and stayed inactive". I learned this the hard way by assuming "inactive" meant the same thing, but I don't want my rule trigger to fire the instant motion isn't detected.
Playing around with Basic Rules, I found the option and see it's exactly what I need. However, I have more complex logic than it appears Basic Rules can handle.
To summarize the use case, the motion sensor turns on lights in a room. I want a lack of motion to turn off the lights, but only if the door's contact sensor is not closed.
A rule like the one pasted below will do what you want. In this rule, the lights are turned on when either a contact sensor is open, or when motion is sensed. The lights are turned off after there has been a lack of motion for 2 minutes IF the contact sensor is not open.
Thank you! I will try using this as a guide for my own rule and follow up later.
Just for my own learning, what impact does the "Cancel Delayed Actions" and the "cancelable" option do?
I tried setting up a rule using "when motion is inactive", with a delay of 30 seconds on my own rule prior to reaching out on this forum, but the problem I ran into was that the lights would almost randomly go off. If I was in the room, then stood still for a moment, then started moving again, from the moment the sensor detected my stillness, the delay started, meaning the lights went off 30 seconds from any time motion ceased, even if motion resumed after. I'm assuming the "canceled" portions keep that from happening.
They ensure that motion active events that occur while the timer to turn the lights off is running will cancel that timer.
Without considering the contact sensor, imagine the following sequence of events:
Motion is active
Lights come on
Motion is inactive
A 2 minute timer is started to turn the lights off EVEN IF there is a motion active event within those two minutes.
The rule actions indicated above account for this possibility:
A motion active event cancels any delayed timers and then turns the lights on (so lights that were previously off turn on, and there's no effect on lights that are already on)
A motion inactive event starts the timer
A motion active event while the timer is running resets the process because the timer is cancelable.
You might also want to take a look at Motion and Mode Lighting. You want the Motion type. There is an option for using a contact switch to control if the rule runs or not. I try to always use one of the "simpler" apps, as they often have an easy way to do what is difficult in RM.