For future reference, that example doesn’t wait for sun.sun to change state to above_horizon. It evaluates the template immediately and produces a result.
wait_template does wait for its template to evaluate to true. However, anything that causes an automation’s actions to wait (like delay, wait_template, wait_for_trigger, repeat, etc) is subject to being terminated if Home Assistant is restarted or Reload Automations is executed.
In other words, if an automation is busy doing something within its action section, it’s vulnerable to being cancelled by a restart/reload. That’s why it’s not a good practice to create an automation that spends many hours (or tens of minutes) within its action section.
Got it…i’ve used similar templates on triggers but yes of course with this syntax will evaluate it immediately. In any case you need to be creative. Thanks mate!
Any idea why i keep getting this rendering error? I’ve tried specifying the triggers and the service on quotes, no quotes, double quotes but always the same error.
Executed: September 3, 2022 at 21:42:19 Error: Template rendered invalid service: switch.turn_
alias: "PLUG: test"
description: ""
trigger:
- id: off
platform: sun
event: sunrise
- id: on
platform: sun
event: sunset
action:
- service: switch.turn_{{ trigger.id }}
data: {}
target:
entity_id: switch.plugsonoff_1_on_off
mode: single
In addition to kbrown’s answer, both on and off in your triggers should be in quotes as shown in 123’s original answer. Those terms have special meanings/functions so the quote marks are important.
Add all the quotes shown in my example and don’t try testing the automation by clicking the Run Actions button. It only runs the actions therefore the trigger variable will be undefined (trigger.id will not exist).
Thank you all for your help…I’m getting familiarized! Is there any way to debug sun.sun triggers? Setting the sun state to “below_horizon” or “above_horizon” doesn’t trigger the automation.