I’m trying to tie a Sonoff SNZB-03 Zigbee PIR motion sensor into my bathroom lights, so that when motion is detected, the lights stay on for 5 minutes after the motion sensor indicates “no motion”.
The sensor works a little non-intuitively as it’s battery powered:
When motion is detected, report binary_sensor state “On” to Home Assistant
When no motion is detected for 60 seconds, report state “Off”
After reporting no motion, wait some time before checking for motion again
I created two automations.
The first triggered in sensor state “On” and only turned the lights on.
The second triggered on a state change to “Off”, waited 2 minutes, then turned the lights off.
This worked - except that if the motion sensor fired an “Off” state, then an “On” state during the 2-minute timer, the “Off” automation would turn the lights off anyway.
I’m trying to figure out how to cancel any running “switch lights off” automations when the “On” automation runs. Failing that - is there a better way to achieve what I want?
I’m very new to writing automations - so far the only one I’ve got working was one which turned my house side-lights on at dusk and off at 1am, again with two automations…
Thanks for the details on this, I am having exactly the same problem but not quite sure how to impliment your solution. If I dont fix this soon I think my wife will lose the plot when the kitchen lights go off again.
Is there any chance you could detail how you have set theis up as it seems to reference scripts?
Thanks