Why's this automation not working?

I can’t for the life of me figure out why this isn’t working, it works fine when either of the conditions is removed (so there’s only the 1 condition)
With them both added the light just stays on
(I’ve removed entity id’s but they are there in real life :rofl:)

alias: Downstairs toilet light off (door & motion sensors)
description: ""
trigger:
  - type: not_opened
    platform: device
    device_id: 
    entity_id: binary_sensor.downstairs_toilet_door_sensor_contact
    domain: binary_sensor
condition:
  - condition: device
    type: is_on
    device_id: 
    entity_id: light.downstairs_toilet_light
    domain: light
  - type: is_no_motion
    condition: device
    device_id: 
    entity_id: binary_sensor.downstairs_toilet_motion_sensor_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 10
action:
  - service: light.turn_off
    data:
      transition: 1
    target:
      entity_id: light.downstairs_toilet_light
mode: single

you need to update your post and add three backticks (```) to the line before and after the code block

Ah sorry about that, first post :+1: sorted now

If I understood your automation correctly it appears that at the moment the bathroom door is closed (after it has been vacated) it turns off the bathroom light but only if the light is already on and, most importantly, no occupancy has been detected for at least the past 10 seconds.

I don’t know how you think the second condition works but here’s how:
The condition doesn’t wait for there to be no occupancy for 10 seconds, it expects it at the moment the door is closed. In other words, starting at least 10 seconds before the door is closed.

The person would have to exit the bathroom without the occupancy detecting any motion for at least 10 seconds prior to closing the door. I don’t see how that can work (unless the occupancy sensor is located in a way that it very quickly loses sight of the person leaving the bathroom).

Thanks for this, made me think about it more basically, I think I’d gone over it so much I was confusing myself and making it more complex than it needed to be haha

I’ve re-done it now so that the trigger is the no motion detected and the conditions are - light on & door sensor in closed position.

All working as I wanted now, thanks for the input

Try this version. It waits for 10 seconds of no occupancy after the door is closed.

alias: Downstairs toilet light off (door & motion sensors)
description: ""
trigger:
  - platform: state 
    target: 
      entity_id: binary_sensor.downstairs_toilet_door_sensor_contact
    from: 'on'
    to: 'off'
condition:
  - condition: state
    entity_id: light.downstairs_toilet_light
    state: 'on'
action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.downstairs_toilet_motion_sensor_occupancy
        to: 'off'
        for: '00:00:10'
    timeout: '00:01:30'
    continue_on_timeout: false
  - service: light.turn_off
    data:
      transition: 1
    target:
      entity_id: light.downstairs_toilet_light
mode: single