Automation Seems to ignore condition

Hi
Im trying to make an automation that turns off the lights 10 min after the door has been closed and no motion has been detected in the meantime. What happens is that as soon as the door closes the lights go off :confused:

alias: Leaving House Lights Off
description: Should turn off all lights when door is closed and no motion is detected
trigger:
  - platform: state
    entity_id:
      - binary_sensor.contact_sensor_ytterdor
    from: "on"
    to: "off"
condition:
  - condition: state
    entity_id: binary_sensor.motion_sensor
    state: "off"
    for:
      hours: 0
      minutes: 10
      seconds: 0
action:
  - type: turn_off
    device_id: 2dbc9efcb9c8172e985847562e06e8e2
    entity_id: light.gaming_room
    domain: light
  - type: turn_off
    device_id: 02cc4ddb954d0f405495eafe97bc41e3
    entity_id: light.living_room
    domain: light
  - type: turn_off
    device_id: c58ba962f5eb7fc912e209de519d738f
    entity_id: light.kitchen
    domain: light
  - type: turn_off
    device_id: a105eacdfa1ba7b31555350f8d5277d2
    entity_id: light.diningroom
    domain: light
mode: single

You need to move the for: to your trigger. As it stands, as long as there has been no motion for 10 minutes when the door closes, the lights will turn off immediately. Depending exactly how you want it to work you may also want to mirror you trigger and condition as follows:

alias: Leaving House Lights Off
description: Should turn off all lights when door is closed and no motion is detected
trigger:
  - platform: state
    entity_id:
      - binary_sensor.motion_sensor
      - binary_sensor.contact_sensor_ytterdor
    from: "on"
    to: "off"
    for: "00:10:00"
condition:
  - condition: state
    entity_id: 
      - binary_sensor.motion_sensor
      - binary_sensor.contact_sensor_ytterdor
    state: "off"
    for: "00:10:00"
action:
  - service: light.turn_off
    target:
      entity_id: 
        - light.gaming_room
        - light.living_room
        - light.kitchen
        - light.diningroom
mode: single

Thanks for the reply :slight_smile:

Hmm, tried the code above, but unfortunately now the lights goes off after 10 minutes no matter if the door went from open to closed :thinking: , The purpose of this is to look for motion after the entrance door is closed to determine whether Iā€™m coming home or leaving. if Iā€™m leaving and no other motion is detected for say 10 min, turn off the entire apartment :slight_smile:

I think there may just be some extra entities in the above recommended trigger and condition, causing the automation to be triggered when no motion was detected for ten minutes regardless of any state change for the door sensor. Does it work better like so?

trigger:
  - platform: state
    entity_id:
      - binary_sensor.contact_sensor_ytterdor
    from: "on"
    to: "off"
    for: "00:10:30"
condition:
  - condition: state
    entity_id: 
      - binary_sensor.motion_sensor
    state: "off"
    for: "00:10:00"

(also added thirty seconds to the door closed timer in case the motion sensor takes a couple seconds to update after the door closed)

Hey, sorry for the late reply, ive tried the code and this seems to keep the lights on permanently. :thinking: will tinker some with the values to test it

Is the automation getting triggered? If it is, can you check the trace and see where it is failing?