I’m trying to display both my current time and my home town.
With a worldclock it’s possible but I’d prefer a 12 hrs format.
With now it’s simple, just {{ now().strftime('%I:%M %p') }}, but with the sensor.worldclock_sensor I cannot get it to work, I’ve tried things like {{ strptime(states('sensor.worldclock_sensor'), '%I:%M %p') }}
sensor.worldclock_sensor doesn’t return a proper datetime object. If I could create one object with America/Caracas as the timezone I could format it.
With strptime, you have to tell it the format of the string you’re passing in, not the format of the output you want. Looking at the code, it looks like it’s just %H:%M.
# Convert state to ptime object
{% set nt = strptime(states('sensor.worldclock_sensor'), "%H:%M") %}
# Convert ptime object back to string in a new format.
{{ nt.strftime("%I:%M %p") }}
What I don’t get is how come they (in the 2 images you’ve shown) are 2 or 3 minutes out from normal time zone offsets ?
I think Venezuela is on a half hour offset, but still … ?
I assume the difference was due to the fact that for the my current time I was using now() in the lovelace-ui, and for the Venezuelan time I was using a sensor. I’ve moved both times to sensors and there’s no out of sync anymore.
Hi,
I’m a new in HA.
But I like your clock card a lot, I’s ve tried several times, but i failes to get it done.
Can you tel me where toe put te code?
I wan t to show (in my case) only the Europe.Amsterdam time zone.
Do you have a kind of step by step installation manual for me??
All help is welcome.