PA_Klaus
(Johan)
October 23, 2022, 6:37pm
1
Hello People,
I am hitting a wall with converting the time format. i have a sensor: sensor.power_highest_peak_time_today
Which gives: 2022-10-23T11:00:00+00:00
I only need and want is the 11:00
I am new with python en coding in HA but this i tried but dit not work
{% set dt = states('sensor.power_highest_peak_time_today') %}
{% time = dt.strftime("%H:%M:%S") %}
{{ time }}
Please help
States are always strings… attributes can be other data types like floats, integers, arrays, or datetime objects, but states are always string. As such, you need to convert them to a datetime object before you can use strftime()
{% set dt = states('sensor.power_highest_peak_time_today') | as_datetime | as_local %}
{{ dt.strftime("%H:%M") }}
PA_Klaus
(Johan)
October 23, 2022, 7:23pm
3
Thanx alot for the extra information that helps me alot!
It worked, now i can ask google when the peak solar time is!
123
(Taras)
October 23, 2022, 9:19pm
4
You can slice the string like this:
{{ states('sensor.power_highest_peak_time_today')[-14:-9] }}