Mattie
(Mattias)
February 9, 2019, 4:56pm
1
{{states.sun.sun.attributes.next_rising}} gives me 2019-02-10T06:39:46+00:00
is it possible to strip the output so that only 06:39:46 remains? I would love that for a sensor
and if possible I would like a sensor template that shows me how many hours of the current day that the sun is above the horizon.If thats even possible…?
tom_l
February 10, 2019, 3:53am
2
Yes. Try this:
{{ states.sun.sun.attributes.next_rising.state.split(' ')[1] }}
I have the following configured and it works for displaying sunrise and sunset times.
sensor:
- platform: template
sensors:
nextsunrise:
friendly_name: 'Next Sunrise'
value_template: >
{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom(' %I:%M%p') | replace(" 0", "") }}
icon_template: mdi:weather-sunset-up
nextsunset:
friendly_name: 'Next Sunset'
value_template: >
{{ as_timestamp(states.sun.sun.…
finity
February 10, 2019, 4:47am
3
Sorry, Tom. That template won’t work to get what they want.
Try this:
{{ (states.sun.sun.attributes.next_rising.split('T')[1]).split('+')[0] }}
But even then I not sure that is what the OP wants since that gives the sunrise in UTC.
This will give it in local time (based on your timezone) and it’s easier to read :
{{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom ('%H:%M:%S') }}
4 Likes
tom_l
February 10, 2019, 4:58am
4
Yeah you’re right. I was using sensor.nextsunrise
when trying in my template editor. Missed the different output format.