Template Time formatting help

Apparently I am having a senior moment here …

I am trying to get sensor.pirateweather_hourly_0h which is UNIX Time to print out just the Hour:Minute PM (%I:%M %p) or even %X

{% set cond0_time = as_datetime(states('sensor.pirateweather_hourly_time_2h'))  %}

works as expected cond0_time outputting 2024-01-20 21:00:00+00:00 but I cant for the life of me recall how to get it into 9:00pm (which would be GMT) but best to get it to local time which would be 4:00pm (EST)

can someone throw me a liferaft … its been a long year today and my brain just isn’t there

Copy-paste this into the Template Editor and confirm it reports the time in the desired format.

{% set cond0_time = (states('sensor.pirateweather_hourly_time_2h') | as_datetime | as_local).strftime('%I:%M %p') %}
{{ cond0_time }}

It converts the sensor’s datetime string into a datetime object then uses the object’s strftime method to display it in %I:%M %p format.

1 Like

Thanks! I was fat fingering way too many things … seriously in need of coffee and/or sleep


1 Like