i have a very basic automation to execute. when door opens, turn light switch on for 5 minutes, turn light switch off afterward. by using delay, here’s my code. light switch does turn on BUT turn off almost within 3 seconds
- id: '1570209701939'
alias: auto light on after 7pm, front door open
trigger:
- entity_id: binary_sensor.front_door
from: 'off'
platform: state
to: 'on'
condition:
- after: '19:00:00'
condition: time
action:
- data:
entity_id: light.zooz_zen22_dimmer_v2_level
brightness_pct: 20
service: light.turn_on
- delay:
minutes: 5
- data:
entity_id: light.zooz_zen22_dimmer_v2_level
service: light.turn_off
The automation looks fine. Throwing a softball but make sure you reload automations or restart after it’s saved. Maybe try defining the delay as a string.
Don’t do this with a delay. If the automation triggers again while waiting in the delay the delay will be skipped and the rest of the actions will execute.
i am very happy to say your suggestion works! so now my code looks like this:
- id: '1570209701939'
alias: Turn on living room when there is movement or front door opens
trigger:
- platform: state
entity_id: binary_sensor.motion, binary_sensor.front_door
to: 'on'
condition:
- after: '10:00:00'
condition: time
action:
- service: homeassistant.turn_on
data:
entity_id:
- light.zooz_zen22_dimmer_v2_level
- service: timer.start
data:
entity_id: timer.living_room
- id: '1570211808181'
alias: Turn off living room 10 minutes after trigger
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.living_room
action:
service: homeassistant.turn_off
data:
entity_id:
- light.zooz_zen22_dimmer_v2_level
The first automation is nearly identical to the one you currently have except it doesn’t start a timer.
- id: '1570209701939'
alias: 'Turn on living room when there is movement or front door opens'
trigger:
- platform: state
entity_id: binary_sensor.motion, binary_sensor.front_door
to: 'on'
condition:
- condition: time
after: '10:00:00'
action:
- service: light.turn_on
entity_id: light.zooz_zen22_dimmer_v2_level
The second automation turns off the light after it has been on for 10 minutes (and the current time is later than 10:00).
- id: '1570211808181'
alias: 'Turn off living room 10 minutes after trigger'
trigger:
- platform: state
entity_id: light.zooz_zen22_dimmer_v2_level
to: 'on'
for: '00:10:00'
condition:
- condition: time
after: '10:00:00'
action:
- service: light.turn_off
entity_id: light.zooz_zen22_dimmer_v2_level