Day duration

Hey all,

is there any easy way to display today’s day duration? The sun component offers only next_sunrise and next_sunset but no attributes for today’s sunrise and sunset.

In my configuration I have something like:

- platform: template
sensors:
  sunrise:
    value_template: '{{ states.sun.sun.attributes.next_rising }}'                                                    
  sunset:                                                                                                            
    value_template: '{{ states.sun.sun.attributes.next_setting }}'

the output looking like

Sunrise: 2017-06-19T03:45:37+00:00
Sunset: 2017-06-18T19:22:31+00:00

but the sunrise is tomorrow’s sunrise. I want to have today’s one and calculate the duration.

Moreover, how would you convert 2017-06-19T03:45:37+00:00 to something more readable (and in the correct timezone), e.g., 5:45?

Thanks!

Here’s what I use:

      sunrise_display:
        friendly_name: Next Sunrise
        value_template: '{% if states.sun.sun %}{{ ((as_timestamp(states.sun.sun.attributes.next_rising)) | timestamp_local) [11:16] }}{% endif %}'
      sunset_display:
        friendly_name: Next Sunset
        value_template: '{% if states.sun.sun %}{{ ((as_timestamp(states.sun.sun.attributes.next_setting)) | timestamp_local) [11:16] }}{% endif %}'
1 Like

Cool, thanks!