Wrong timezone for timestamp_local filter

For some reason I can’t get my timestamps displayed in my local timezone and i’m getting out of new things to try.

When testing this template:

last_changed:     {{ states.sensor.laundry_running.last_changed }}
timestamp_local:  {{ states.sensor.laundry_running.last_changed | timestamp_local }}
now:              {{ now() }}
tzinfo: {{ (states.sensor.laundry_running.last_changed | timestamp_local ).tzinfo }}

It gives the output:

last_changed:     2018-07-02 12:37:57.804306+00:00
timestamp_local:  2018-07-02 12:37:57.804306+00:00
now:              2018-07-02 14:39:49.001038+02:00
tzinfo: UTC

So now() displays the time in the correct timezone, but the timestamp_local filter uses UTC time.

I have tried setting the variable TZ globally but it didn’t have any effect on the templates whatsoever, even after a system reboot.

$ echo $TZ
Europe/Stockholm

Any ideas how I can fix this?

well you arent feeding the timestamp_local a timestamp, you are feeding it a datetime. So no filter is occuring, it’s just returning the current datetime that it is provided. I’m guessing you just want the correct time and you don’t really care about tzinfo being correct as long as the time is correct.

So, in order to do this ‘properly’, this is what you want:

timestamp_local:  {{ as_timestamp(states.sensor.laundry_running.last_changed) | timestamp_local }}
2 Likes

That worked perfectly, thanks!

To display timestamp_local right, I had to set proper TimeZone in Settings \ System\ General