I cant turn off our lights (motion sensors)

Hi there,
after trying out a lot of things that worked sometimes or not at all, I would be grateful for some advice. We have stairwell light groups and different motion sensors (Tradfri/Sonoff RF motion sensors/Sonoff Switches with ESPhome+HCSR501). In general the hardware works but I cant get the off-automation properly triggered. Basically it should be: If all sensors are clear for X seconds, turn the lights off. In other words: While motion is detected, leave the lights on; when not, turn them off after X seconds. Or: When motion is detected, delay the off-command by X seconds… I think you get it :wink:
Here is our/one yaml (only with 2 sensors for testing purposes). Thanks guys!

- id: '1632393316283'
  alias: Light Off Floor Three
  description: ''
  trigger:
  - platform: state
    entity_id: group.stairwell_floor_three
    to: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
  condition:
  - condition: state
    entity_id: binary_sensor.pir_sensor_7
    state: 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - condition: and
    conditions:
    - condition: state
      entity_id: binary_sensor.pir_sensor_10
      state: 'off'
      for:
        hours: 0
        minutes: 0
        seconds: 10
        milliseconds: 0
  action:
  - service: homeassistant.turn_off
    target:
      entity_id: group.stairwell_floor_three
  mode: single```

The way you’ve written that:

  1. When group.stairwell_floor_three turns on
  2. And binary_sensor.pir_sensor_7 has been off for 10 seconds
  3. And binary_sensor.pir_sensor_10 has been off for 10 seconds
  4. Turn off group.stairwell_floor_three

Oh, and that and condition isn’t doing what you think it is. You’ll likely want to re-read the docs on that.

That’s not what you said you wanted. Remember, triggers are the thing that start an automation - conditions are then checked. This is likely what you really wanted:

- id: '1632393316283'
  alias: Light Off Floor Three
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.pir_sensor_7
    to: 'off'
    for: '00:00:10'
  - platform: state
    entity_id: binary_sensor.pir_sensor_10
    to: 'off'
    for: '00:00:10'
  condition:
  - condition: state
    entity_id: group.stairwell_floor_three
    state: 'on'
  - condition: state
    entity_id: binary_sensor.pir_sensor_7
    state: 'off'
    for: '00:00:10'
  - condition: state
    entity_id: binary_sensor.pir_sensor_10
    state: 'off'
    for: '00:00:10'
  action:
  - service: homeassistant.turn_off
    target:
      entity_id: group.stairwell_floor_three
  mode: single

If you’re writing it in YAML you can collapse it though:

- id: '1632393316283'
  alias: Light Off Floor Three
  description: ''
  trigger:
  - platform: state
    entity_id: 
    - binary_sensor.pir_sensor_7
    - binary_sensor.pir_sensor_10
    to: 'off'
    for: '00:00:10'
  condition:
  - condition: state
    entity_id: group.stairwell_floor_three
    state: 'on'
  - condition: state
    entity_id: 
    - binary_sensor.pir_sensor_7
    - binary_sensor.pir_sensor_10
    state: 'off'
    for: '00:00:10'
  action:
  - service: homeassistant.turn_off
    target:
      entity_id: group.stairwell_floor_three
  mode: single

Thank you very much, thats what I was looking for. :slight_smile: