Simple add-time template starting with wrong start time

Ok, I’m not seeing where the top template code is getting the value of 18:53:00?!?


{{ (state_attr('input_datetime.last_walk_date_time', 'timestamp') + 21600) | timestamp_custom('%-I:%M %p') }}

{{states.input_datetime.last_walk_date_time.state}}

The values I’m getting here are:

  • 12:53 AM
  • 23:53:00

So the input_datetime.last_walk_date_time is showing the correct state value at 23:53:00. But the top template is supposed to be adding 6 Hours to that ( + 21600 ) , instead its adding only 1 hour — well technically, it is adding 6 hours, but from this mysterious 18:53:00 timestamp it somehow has??

Now if i remove the + 21600 i get a value of 6:53 PM. So where is that input_datetime getting that time from/??

Below I stripped out the addition of time just to show the two different times coming from the same input


{{ state_attr('input_datetime.last_walk_date_time', 'timestamp') | timestamp_custom('%H:%M:%S') }}

{{states.input_datetime.last_walk_date_time.state}}

timestamp_custom takes a timestamp (seconds since 1970-01-01) which is assumed to be in UTC and converts it to local time by default (docs).

However, your input_datetime's timestamp attribute is passing it a non-UTC (“timezone-naive”) timestamp in seconds since the start of the day (85980). By default, timestamp_custom will assume that is 1970-01-01T23:53:00Z (seven minutes to midnight UTC), so you should provide the localtime=False argument to stop it applying your timezone conversion to it:

{{ (state_attr('input_datetime.last_walk_date_time', 'timestamp') + 21600) | timestamp_custom('%-I:%M %p', False) }}

I’d imagine that a) you’re in a UTC-5 timezone and b) that will solve your problem.

And I learn something new everyday. That fixed it right up.
I had no clue about the UTC incorporation in my tenplates like this; i just assumed it took the value of the input_datetime and did the calculations based off just that.

Thanks for helping me out with this.

1 Like