I have the following automation set up to turn on a dimmer switch when motion is detected. But for some reason when it detects motion a second time it turns the dimmer switch off. Why would light.turn_on act like a toggle?
- id: Turn on Front Light for 20min on motion
alias: 'Motion Stairs-Front Light On 20min'
trigger:
platform: state
entity_id: binary_sensor.fibaro_motion_front_motion
to: 'on'
action:
- service: light.turn_on
data:
entity_id: light.front_dimmer
brightness: 100
- delay: '00:20:00'
- service: light.turn_off
data:
entity_id: light.front_dimmer
@tom_l thanks for the explanation. I would have expected the timer to be cancelled but the remaining portion to either run before the new triggered actions or not run at all. Either would have worked. I don’t think it was the trigger that cancels the timer but rather the second timer request. So basically on first motion you get
light on
delay pending…
on second motion you get
light on
delay pending…
-first delay canceled
first turn off action taken (leaving the light off)
I was able to fix this by adding the following to my rule.
condition:
- condition: state
entity_id: light.front_dimmer
state: 'off'
This prevents the trigger from happening until the delay finishes and the light is turned off.
Your idea would have worked for the second motion but it would resulted in the second time the motion stops the light would still turn off. It would not wait 20 minutes as I wanted.
Your help still got me to a solution so many thanks!
No because your explaination made me realize how to fix my single rule. I missed the for: 20 in your rule so you are correct. Your two rules would work also, sorry about that. Thanks again for your help.