If the automation triggers again while it’s still running from the first trigger, and it’s “sitting” in the delay, the delay gets canceled and it continues from there. Which means if the motion sensor detects motion and goes ‘on’, then goes ‘off’, and then motion is detected again two minutes after it first detected motion, the automation will get triggered a second time while it’s still running from the first trigger, causing the delay to get canceled and the next step to run which turns off the lights.
The way to deal with this is to move the actions into a script, then in the action part of the automation, first “turn off” the script (i.e., cancel it), then start it. This will cause the script to start from the beginning. So…
Automation:
- alias: Accendi Luce Studio Sera
initial_state: on
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d0001ddac9e
to: 'on'
condition:
condition: or
conditions:
- condition: sun
after: 'sunset'
after_offset: "00:10:00"
- condition: time
before: 00:05:00
action:
- service: script.turn_off
entity_id: script.lights_on_7min
- service: script.lights_on_7min
Thank you for this post!
I had a problem with my automation switching off when motion is triggered for the second time and your explanation helped me to realise what was going on. Running it as a script sorted that right out.
Thanks!
You might be interested in this post where I provide two solutions - the same one as here, and another that ignores further triggers while the script is still running.