Motion lighting automation problem

I thought I could try to ‘shortcut’ an automation (having a delay and then ‘off’ action all in one) using the below code and the light will turn on when motion is detected and run for the delay time before turning off, as expected, however if motion is detected a second time the light instantly turns off… why would this be? can I not code automations like this?

configuration.yaml
automation: !include_dir_list automations

passage_night_light.yaml (in automations directory)

alias: Passage Night Light
trigger:
  - platform: state
    entity_id: binary_sensor.passage_multi_sensor_sensor
    to: 'on'
condition:
  condition: or
  conditions:
  - condition: sun
    after: sunset
    after_offset: '00:30:00'
  - condition: sun
    before: sunrise
    before_offset: '00:15:00'
action:
  - service: homeassistant.turn_on
    entity_id: light.gateway_light_34ce008d5245
  - delay: '00:01:00'
  - service: homeassistant.turn_off
    entity_id: light.gateway_light_34ce008d5245

You can find a similar automation to what you are trying to achieve here:

I tried copying that for my kitchen light but that one doesnt work at all. Given that this passage light kind of works I figured maybe i was somewhat closer to a solution with it

Your automation is perfect for turning it on. Remove the delay and the turn_off create a separate ‘off’ automation.

The key part in the example in the link above is the trigger:

trigger:
  platform: state
  entity_id: binary_sensor.passage_multi_sensor_sensor
  to: 'off'
  for:
    minutes: 10

This will only trigger when your sensor has been off for 10 minutes straight. Any interruptions invalidate the trigger and it starts waiting again next time the sensor reports ‘off’.

I have made some changes but it still doesnt not work. This is what I have for my kitchen light ON automation:

alias: Kitchen light auto ON motion
trigger:
  - platform: state
    entity_id: binary_sensor.kitchen_multi_sensor_sensor
    to: 'on'
#condition: or
condition:
  - condition: sun
    after: sunset
#    after_offset: '00:00:00'
  - condition: sun
    before: sunrise
    before_offset: '00:30:00'
action:
  - service: homeassistant.turn_on
    entity_id: light.kitchen_light_level
    data:
      brightness: 100

then for the OFF automation I have this (which does work!):

alias: Kitchen light OFF after 2mins
trigger:
  - platform: state
    entity_id: binary_sensor.kitchen_multi_sensor_sensor
    to: 'off'
    for:
      minutes: 2
action:
  - service: homeassistant.turn_off
    entity_id: light.kitchen_light_level

ok, I think I have got it sorted with:

alias: Kitchen light auto ON motion
trigger:
  - platform: state
    entity_id: binary_sensor.kitchen_multi_sensor_sensor
    to: 'on'
condition:
  condition: or
  conditions:
    - condition: sun
      after: sunset
#    after_offset: '00:00:00'
    - condition: sun
      before: sunrise
      before_offset: '00:30:00'
action:
  - service: homeassistant.turn_on
    entity_id: light.kitchen_light_level
    data:
      brightness: 100
1 Like