Presence detection(ish) with Motion Sensors

My house has already about dozen motion detectors and and I’m not going to update those to presence detectors anytime soon. So I wrote some logic so HA might have a better guess about where the people are.

I divided my house into zones. The map is not in scale, but shows how zones are connected to each other.

Every room/zone has own presence detection logic, that simple checks when was the last movement detected in zone or the zones connected to it. If the last movement was in zone, then there is someone. If the last movement is in the connected zone, then the current zone is marked ‘empty’.

The motion sensors have a couple of minutes delay before they sent ‘no-movement’ and then it’s last_movement is set as (now-delay). Because of that delay, the presence detection is always a little bit behind but the main thing is it’s up to date when HA has to make decision to shut down lights in your current room. No more waving your hands to get some light.

The logic is not perfect if there is more than one person, because if persons are in separate zones that are connected, the presence detection sees it as one person moving between the zone back and forth. But this is only problem if persons do not move and no motion is detected. If motion detector has detected motion, the room is always marked as occupied.

One example is the person A is in the kitchen and person B moves to Working Room. Then if person A does to move, the kitchen’s presence detection ( after delay ) sets kitchen as ‘empty’ and person A has to wave those hands to set motion detector on.

Motion sensor last_moved template sensor, delay is set for 240s.

      - name: "Pool Room Motion Sensor Last Moved"
        state: >-
          {% if is_state('binary_sensor.pool_room_motion_sensor_home_security_motion_detection','on') %}
            {{ max(( now() - timedelta(seconds = 120)), states.binary_sensor.pool_room_motion_sensor_home_security_motion_detection.last_changed ) | as_timestamp}}
          {% else  %}
            {{ (( states.binary_sensor.pool_room_motion_sensor_home_security_motion_detection.last_changed ) - timedelta(seconds = 120) ) | as_timestamp }}
          {% endif  %}
        availability: "{{ states('binary_sensor.pool_room_motion_sensor_home_security_motion_detection') not in ['unavailable', 'unknown', 'none'] }}"

Presence detection binary-sensor:

      - name: "Pool Room Presence"
        state: "{{  (states('sensor.pool_room_motion_sensor_last_moved') > states('sensor.hall_combined_motion_sensor_last_moved')) and (states('sensor.pool_room_motion_sensor_last_moved') > states('sensor.swimming_pool_motion_sensor_last_moved'))}}"
        availability: "{{ states('sensor.pool_room_motion_sensor_last_moved') not in ['unavailable', 'unknown', 'none']  and states('sensor.swimming_pool_motion_sensor_last_moved') not in ['unavailable', 'unknown', 'none']  and states('sensor.hall_combined_motion_sensor_last_moved') not in ['unavailable', 'unknown', 'none'] }}"

1 Like