Files
fresh-home/components/sensors/sun_elevation.yaml
T
2025-12-03 20:23:33 -05:00

38 lines
1.3 KiB
YAML

template:
- sensor:
- unique_id: templatesensor.sun_elevation
unit_of_measurement: degrees
default_entity_id: sensor.sun_elevation
icon: >
{% set elevation = state_attr('sun.sun', 'elevation')|default(0) %}
{% if elevation > 0 %}
mdi:weather-sunny
{% else %}
mdi:weather-night
{% endif %}
state: '{{ state_attr("sun.sun", "elevation") }}'
name: sun_elevation
- unique_id: templatesensor.period_of_day
default_entity_id: sensor.period_of_day
name: Period of the Day
state: >-
{% if (as_timestamp(states.sun.sun.attributes.next_dusk)) - (as_timestamp(states.sun.sun.attributes.next_setting)) < 0 %}
Dusk
{% elif (as_timestamp(states.sun.sun.attributes.next_rising)) - (as_timestamp(states.sun.sun.attributes.next_dawn)) < 0 %}
Dawn
{% elif (states.sun.sun.attributes.elevation) < -4 %}
Night
{% else %}
Day
{% endif %}
icon: >
{% if is_state("sensor.period_of_day", "Dawn") %}
mdi:weather-sunset-up
{% elif is_state("sensor.period_of_day", "Dusk") %}
mdi:weather-sunset-down
{% elif is_state("sensor.period_of_day", "Night") %}
mdi:moon-waxing-crescent
{% elif is_state("sensor.period_of_day", "Day") %}
mdi:weather-sunny
{% endif %}