I would like to write an automation to turn on a switch between 18:30 and 19:45; but if sunset is later than 18:30, at sunset but still by 19:45. Is the following correct:
triggers:
- trigger: template
value_template: "{{ sun.sunset and now() > today_at('18:30') }}"
- trigger: time
at: "19:45:00"
If not, would someone please show me the proper code. Note that it doesn’t matter if the switch gets turned on twice.Thanks.
FWIW, I wouldn’t use this Template Trigger (even after its syntax error is corrected) because it’s less efficient than Didgeridrew’s suggestion.
Your template contains now() and today_at() so Home Assistant will evaluate the template every minute (because the values of now() and today_at() change at 1-minute intervals when used in templates). In contrast, Didgeridrew’s version is evaluated just three times a day (at sunset and at two scheduled times).