Smart room presence?

Hi,

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)

I use some automations for this.

an example:

alias: Raaf ledstrip uit pir
description: ''
trigger:
  - type: no_motion
    platform: device
    device_id: bd3b03f2e3c1bd71519e781ffdee36b2
    entity_id: binary_sensor.neocam_pir_raaf_home_security_motion_detection
    domain: binary_sensor
    for:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
condition:
  - condition: state
    entity_id: light.raafledstrip
    state: 'on'
action:
  - service: switch.turn_off
    target:
      entity_id: switch.sonoff_10008c3a5b_2
mode: single

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.

I currently have the following template sensor:

- binary_sensor:
    - name: Aanwezig myroom
      state: >
        {{ is_state('binary_sensor.beweging_myroom_presence', 'on') }}
      delay_on: 00:05:00
      delay_off: 00:30:00

which does the job partially. (only the ‘off’ goes as I want. The ‘on’ really depends my motion sensor to constantly push a ‘on’)

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.

If they are all the same, the person has not left the room. If the value of the variable is different from the history attributes, they have.

1 Like

How does that work when there are more than 1 person in the house, and they move independent in the house ?

Damn. I live alone, of course… And I was so pleased with the idea. :roll_eyes:

In that case you would create two variables I suppose :slight_smile:

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.

3 Likes

Do you also take in account if someone ‘stays’ in the room?

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.

:grinning:

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

Maybe you can share your automation?

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.