Sometimes the elevation that fits the sunset isn’t just right for sunrise. For those situations, as the title describes
sensor:
#My Sun
- platform: template
sensors:
my_sun:
entity_id: sun.sun
value_template: >
{% if is_state_attr('sun.sun', 'rising', True) and state_attr('sun.sun', 'elevation')|float > -4.4 %}
above_horizon
{% if is_state_attr('sun.sun', 'rising', False) and state_attr('sun.sun', 'elevation')|float > -1.5 %}
above_horizon
{% else %}
below_horizon
{% endif %}
this is the same
sensor:
#My Sun
- platform: template
sensors:
my_sun:
entity_id: sun.sun
value_template: >
{% if (is_state_attr('sun.sun', 'rising', True) and state_attr('sun.sun', 'elevation')|float > -4.4 ) or (is_state_attr('sun.sun', 'rising', False) and state_attr('sun.sun', 'elevation')|float > -1.5 )%}
above_horizon
{% else %}
below_horizon
{% endif %}
you can even put weather conditions (cloudy, partly-cloudy, etc), openweathermap updates every 10 minutes I believe and it’s fairly accurate