I have an automation that triggers outdoors light when I get home and the sun has set.
I want them to stay or for 15 minutes or so while I unpack the car.
I got the first automation working thanks to you guys, but this one has me stumped as I’m not sure why the condition is coming up as false even though looking at it through dev tools shows me it is true.
alias: Welcome home "off"
description: Turn off lights 15 minutes after welcome home automation was triggered
trigger:
- platform: state
entity_id:
- automation.welcome_home
condition:
- condition: state
entity_id: switch.lumieres_ext_entree
state: 'on'
for:
hours: 0
minutes: 15
seconds: 0
action:
- type: turn_off
device_id: 838c487b0380cd5fc80542d5da2ee686
entity_id: switch.lumieres_ext_entree
domain: switch
mode: single
Trace log reports this:
entity_id/0
Executed: July 16, 2022, 8:32:32 AM
Result:
result: false
state: 'off'
wanted_state: 'on'
Would this simply have to do with the fact that my lights are not on at the moment the other automation runs, since that is my trigger?
I believe your condition is what is causing the issue since the automation is only on during the time it runs.
So either remove condition and add a delay as the first action of 15 minutes.
Or you trigger on the light on for 15 minutes and have condition after sun down.
Here’s an example of avoiding the “domino” technique of one automation triggering another.
It’s based on the automation you created in your other topic and simply enhances it with the ability to turn off the lights after 15 minutes.
alias: Control outside lights
description: Turn on when we come home at night and off 15 minutes later
trigger:
- id: 'on'
platform: state
entity_id:
- device_tracker.iphone_ian_2
- device_tracker.wok_2
to: 'home'
- id: 'off'
platform: state
entity_id: switch.lumieres_ext_entree
from: 'off'
to: 'on'
for:
minutes: 15
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- service: 'switch.turn_{{ trigger.id }}'
target:
entity_id: switch.lumieres_ext_entree
mode: single
NOTE
Be advised that any automation that relies on the use of delay, for, wait_template, wait_for_trigger, etc cannot survive a restart of Home Assistant or a reloading of automations. In other words, if Home Assistant is restarted while an automation’s 15-minute delay is counting down, the automation is cancelled and reloaded thereby terminating the delay. Whatever action comes after the delay is never executed.
FWIW, there are programming techniques, employing an input_datetime or a timer, that make time delays immune to restarts/reloads.