Rather than an automation to turn on a light at sunset (+/- some offset), and then a second to turn it off at sunrise (+/- offset), can’t we use “below horizon” as a stand in for “dark”? I’d want a single automation that says “while dark turn on if off, else turn off if on”.
So I suppose the basic question is are “do while” loops available for automations, and how often does it loop to check the status of “dark”?
You can do that with templates. That does mean that your single automation is harder to debug and maybe harder to read though:
- alias: 'Make the lights chase the sun'
trigger:
# Use only of these
# Triggers when the sun goes above/below the horizon
- platform: state
entity_id: sun.sun
# Triggers when the sun goes above/below the defined elevation
- platform: value_template
value_template: "{{ state_attr('sun.sun','elevation')|int < -3 }}"
action:
- service_template: >-
{% if is_state('sun.sun','above_horizon') %}
light.turn_off
{% else %}
light.turn_on
{% endif %}
data:
entity_id: light.your_light
And as has been said, no. Home assistant is event based.