I’m looking for a ‘intelligent’/‘smart’ way to detect 'occupancy in a room. I have motion detectors in all of my rooms (mostly for usage as thermometers).
The motion detector obviously doesn’t constantly ‘see’ the person(s) in the room. It usually goes off and on every so many minutes/seconds.
So I want to have a ‘room occupied’ state when someone is in the room from 5 minutes or longer and let’s say up to 30 minutes after the last person leaves.
The end-purpose is to switch off lights if someone forgets to switch off the lights after leaving the room and to turn down the thermostat when no-one is in the room, or to turn it up when someone stays in the room.
So, it shouldn’t be triggered if someone walks into the room, waters a plant and walks out again. (( it of course doesn’t have to be flawless. It’s possible that the room is ‘occupied’ longer than needed if someone is in the room for 5 minutes and 10 seconds ))
Edit: For completeness. I did find some Node-Red based things, or using external software. I am looking for a solution which lives solely in native HA (it can be a HACS module if applicable)
Yes, that would work nicely with for the ‘leaving’ part of it. But not for the ‘arriving’ as it’s possible that the motion sensor doesn’t constantly detect a person for more than x-minutes.
In HACS there is an integration called Variables+History, which you can use in conjunction with motion sensors to create a variable holding the name of the room where motion was last detected. Besides it’s value, this variable has three attributes containing the last locations where motion was detected.
I approach this a little different than most people I think. In my model, I am counting the number of times a person is detected within a certain amount of time under certain conditions. Slowly increasing the ‘timeout’ of the room occupancy.
I use three levels of occupied. Active, Occupied and Camped. Each state has a defined timeout to vacancy.
It’s a little nebulous, but each room takes into consideration how my people detectors there are. Once a threshold of active counts is reached I transition the room to the next level. For rough example in a bathroom where only 1 person detector exists, if that detector goes active 3 times within the ‘Active’ timeout threshold, then I transition the room to Occupied from Active. Occupied timeout threshold is longer and the number of detections required to move to Camped is higher than is Active to Occupied.
It’s a little hard to explain, but that’s it basically. I find this fairly reliable for determining if people are staying in a room or just passing through the area.
I have considered that, but no. I haven’t found it necessary. The fact is, whether they stay or not the person detector is going on and off constantly, so counting up the number of occurrences within a certain threshold is enough for me to extend the timeout threshold. Not perfect, but good enough that the lights aren’t typically going off when they shouldn’t.
EDIT:
You inspired me to revisit. I have now added a periodic check if a person detector stays active, and reaches the threshold I determine, the occupancy type will transition.
This sounds interesting. Do you still do it this way or did you improve on it? I am looking to do the same thing. I guess you use the wait using wait-template with timeout ( Script Syntax - Home Assistant ) for a new trigger from the motion sensor?
if motion sensor triggered before the timeout you increase a counter. And if counter above a certain level you change to the Occupied or Camped and increase the timeout accordingly
if timeout happened decrease the counter, and when counter is 0 you switch off the light
No, I don’t do it anymore. Firstly I gave up on the C# integration, (the integration was failing and the creators were stumped why) I was using the write the code and with it all the automation that I’d created. Second, with the advent of mmWave, it’s really kind of unnecessary now.