I am trying to automate lights in the bathroom based on room occupancy flag, using a single motion and a door sensor.
My motion sensor (Aqara) is pretty slow and changes to state “no_motion” exactly 70 seconds after the motion stopped, so I want to use that to detect if it was possible for the person to leave (the door was open) 70 seconds ago, when the event “no motion” comes.
But how do I add a condition to check if the state of door was “open” -70 seconds ago?
I can’t check for duration because the door is usually closed after leaving the room (bathroom), but not always.
You can test the last_changed
attribute of the door sensor to check when the state was, well, last changed.
Thanks, will look in to my options using this.
At a first glance it looks bit complicated to construct a rule that ends up checking the state at given time. The problem is that there may be doors opened and closed at various times, even after motion has stopped. Those with small kids will understand what the usual traffic looks like.
Maybe look for a motion sensor that meets your need better?
That video reviews the most common ones, including the time they take to move from "motion detected’ to “no motion”.
I believe I have found a solution. I am doing an OR check whether the door was open longer than 70 seconds, or closed no longer than 70 seconds. This is not exactly what I needed, but it works in both scenarios, when someone exited the room and closed the door, or left the door open.
This is working pretty reliably now and I heard no criticism from the wife, which is unbelievable.