Suggestions on how to turn of light after two motions sensors are both clear for 3 minutes

- alias: Bathroom Main Lights off
  hide_entity: true
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_sensor_158d00022548e0
      to: 'off'
      for:
        minutes: 3
  condition:
    - condition: state
      entity_id: binary_sensor.motion_sensor_158d0000ef8616
      state: 'off'
      for:
        minutes: 3
  action:
    service: switch.turn_off
    entity_id: switch.BathLights

This what I currently have and get no errors in check config, however now the light refuses to automatically turn off. If I removed the condition section then it will turn off after one the 1st sensor detected no movement for 3 minutes however I need it to be off when both sensors detect no movement.

Any Jedi masters of the Home Assistant world got any better ideas?

Make a template sensor that combines the state of both motion sensors. Trigger on that, no condition.

binary_sensor:
  - platform: template
    sensors:
      movement:
        value_template: '{{ is_state("binary_sensor.motion_sensor_158d00022548e0", "on") or is_state("binary_sensor.motion_sensor_158d0000ef8616", "on") }}'

automation:
- alias: Turn off without movement
  trigger:
    - platform: state
      entity_id: binary_sensor.movement
      to: 'off'
      for:
        minutes: 3
  action:
      service: switch.turn_off
      entity_id: switch.bathlights
1 Like

You Sirs are a legend. Although after some testing it was already working with my code but I am certainly going to use your code because it is cleaner.

In your code does the template state need to be changed to off? I think it does.

No changes. I edited to add the automation part.

Your automation above only triggers on one motion sensor so it does not work as intended.

You need to have both sensors off in value template and change or to and.

{{ is_state("binary_sensor.motion_sensor_158d00022548e0", "off") and is_state("binary_sensor.motion_sensor_158d0000ef8616", "off") }}

Then you should also rename it to “no movement” because it is just the opposite binary sensor. However, too many negatives will make you go crazy so I suggest to just stick with the “movement” sensor and test for it going to “off”.

Thanks guy I got enough to move forward.

worked a treat with code as is. Changing to an OR statement broke it for some reason, guessing the logic was the issue.

thanks for the help much appreciated.