Templating for motion sensor - occupancy sensor for a hallway

Hi.
I have a long hallway with 3 motion sensors that activate and deactivate the lights in the hallway based on no motion detected for 30 seconds. In general it works fine, but of course if you are standing still in the hallway or having little movement the lights will go off and you should start moving your arms like you are the director of a philarmonic. Also, its not very consume efficient since most of the time the lights should not be on for more that 5-10 seconds, so I’m triying to improve this.

The hallway has 3 motion sensors that detect motion perfectly comming out of any room, and every room has a motion sensor that detects motion when comming into the room. The three sensors are grouped with a helper.


What I would like to achieve is that:

  • The hallway light turns on when the motion group is on
  • The hallway light turns off when comming into a room and does not detect motion in the hallway for lets say 5 seconds
  • The hallway light will not turn off unless I get into a room or past 5 minutes as a failsafe
  • That failsafe of 5 minutes will not run if the door leading out of the house at the end of the hallway is open

I’ve managed so far to turn on the light whith motion and turn it off when comming into a room, but it fails from time to time since the timeout on my sensors is 5 seconds and if I come into a room just to pick up something and get out, the automating will not render the condition as true, since the hallway gruop has not had time to be off.

Please check my automation to see if anyone can come with a solution.

- id: Turn on and off hallway lights with motion sensor
  alias: Turn on and off hallway lights with motion sensor
  description: ''
  trigger:
  - entity_id: binary_sensor.sensores_de_movimiento_del_pasillo
    platform: state
    to: 'on'
  condition: []
  action:
  - data: {}
    service: light.turn_on
    target:
      entity_id:
      - light.luz_del_pasillo
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.sensores_de_movimiento_del_pasillo
      to: 'off'
  - condition: and
    conditions:
    - condition: or
      conditions:
      - type: is_motion
        condition: device
        device_id: 73e48e0f6c3f7d365cd776e6bf6ff9f2
        entity_id: binary_sensor.sensor_de_movimiento_de_la_cocina_occupancy
        domain: binary_sensor
      - type: is_motion
        condition: device
        device_id: 32f91552ae4bd4296b7c5e3487d815b0
        entity_id: binary_sensor.sensor_de_movimiento_del_bano_de_juan_occupancy
        domain: binary_sensor
      - type: is_motion
        condition: device
        device_id: 4feb07e46cb0fa3fba0e54d179df1ce7
        entity_id: binary_sensor.sensor_de_movimiento_del_bano_de_amaia_occupancy
        domain: binary_sensor
      - type: is_motion
        condition: device
        device_id: b8ed49319b3048d22928c2c89c6b464a
        entity_id: binary_sensor.sensor_de_movimiento_del_cuarto_de_la_entrada_occupancy
        domain: binary_sensor
      - type: is_motion
        condition: device
        device_id: 1cccca38a8e65723fcdcf7965e625101
        entity_id: binary_sensor.sensor_de_movimiento_del_salon_occupancy
        domain: binary_sensor
  - service: light.turn_off
    data: {}
    target:
      entity_id:
      - light.luz_del_pasillo
      - light.fairy_lights
  mode: restart

There is also the aqara occupancy sensor which should come out soon
Aqara Prepare Launch of Next Gen Occupancy Sensor – Homekit News and Reviews

1 Like