platform: template sensors: sun_elevation: unique_id: templatesensor.sun_elevation value_template: "{{ state_attr('sun.sun', 'elevation') }}" unit_of_measurement: "degrees" icon_template: > {% set elevation = state_attr('sun.sun', 'elevation')|default(0) %} {% if elevation > 0 %} mdi:weather-sunny {% else %} mdi:weather-night {% endif %} period_of_day: unique_id: templatesensor.period_of_day friendly_name: Period of the Day value_template: >- {% 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 %}