Timer finished one hour out of sync

Hi,

I’m having issues with timers being one hour out of sync, I’m in the UK GMT with DST.

Wake Window Timer via dev tools states finishes at 21:31

duration: '3:00:00'
editable: true
finishes_at: '2023-05-04T21:31:48+00:00'
remaining: '2:25:04'
restore: true
icon: mdi:baby-face
friendly_name: Wake Window Timer

But the timer itself states;

Attributes
Duration
3:00:00
Finishes at
May 4, 2023 at 10:31:48 PM

Logs are and all other aspects of HA are showing correct time - Just this that is out and casuing issues when trying to report\use via jinja.

Via templates I get this;

{{ now() }}
{{ utcnow() }}

Result type: string

2023-05-04 21:36:05.746473+01:00 
2023-05-04 20:36:05.746483+00:00

Any help would be appreciated.

Thanks

You need to pay attention to the + in the timestamps.

21:31+00:00 is 10:31pm in GMT with DST active, because GMT with DST is +01:00

Thanks bud. I do see that in the templates as well - sorry noob over here but do you know how I would resolve it?

This is one of my usages;

service: input_datetime.set_datetime
entity_id: input_datetime.wake_up_time
data_template:
  datetime: "{{ state_attr('timer.wake_window_timer', 'finishes_at') }}"

Thanks again

There’s nothing to resolve — it’s just different representations of the same time.

If you’d like the time formatted in a specific way in your front end, then provide full details including hte code that’s generating it.

Note that you should use data: instead of data_template: these days.

Thanks for your time and comments mate.

So I have a 3 hour timer via a helper. I’m looking to send a notty to my phone when it starts the finish time. I have the below so far.

service: notify.mobile_app_pixel
data:
  message: "{{ state_attr('timer.wake_window_timer', 'finishes_at') }}"

This gives me the 3 hour duration but an hour out (i.e. less one hour)

"2023-05-05T11:41:34+00:00"

So I tried adding it to a time helper as below;

service: input_datetime.set_datetime
entity_id: input_datetime.wake_up_time
data_template:
  datetime: "{{ state_attr('timer.wake_window_timer', 'finishes_at') }}"

But again this results in same issue as below;

image

This is what the timer is reporting under attributes;

image

Again sorry for the noob questions just can’t work it out, cheers.

You need to format your time.

I can not make the code where I am, but look at the first post in this thread.

Thanks so much so been trying my best but can’t get the formatting correct, what am I missing.

service: notify.mobile_app_pixel
data:
  message: "{{ state_attr('timer.wake_window_timer', 'finishes_at', '%Y-%m-%dT%H:%M:%S+00:00'))) }}"

Invalid action

template value should be a string for dictionary value @ data[0][‘data’]

I also just added it like the below but again get an error;

service: notify.nursing
data:
  message: "{{ state_attr('timer.wake_window_timer', 'finishes_at', '%Y-%m-%dT%H:%M:%S+00:00'))) }}"{{ (as_timestamp(now()) - as_timestamp(strptime(states('timer.wake_window_timer', 'finishes_at'), '%Y-%m-%dT%H:%M:%S+00:00')))|int }}"

Invalid action

template value should be a string for dictionary value @ data[0][‘data’]

OK

Thanks again

service: notify.mobile_app_pixel
data:
  message: "{{ strptime(state_attr('timer.wake_window_timer', 'finishes_at'), '%Y-%m-%dT%H:%M:%S+00:00') }}"

Break it down to see what’s going on. Your version had way too many close brackets. This is equivalent and makes it easier to read:

  message: >
    {{ strptime(
         state_attr('timer.wake_window_timer', 'finishes_at'),
         '%Y-%m-%dT%H:%M:%S+00:00'
       ) }}

Brilliant and thanks gain, so that now works but still give me the wrong time an hour behind.

  message: >
    {{ strptime(
         state_attr('timer.wake_window_timer', 'finishes_at'),
         '%Y-%m-%dT%H:%M:%S+01:00'
       ) }}

So I added “01:00” as assumed that would correct it but get the below error;

Error running action

Error rendering data template: ValueError: Template error: strptime got invalid input ‘2023-05-05T13:49:05+00:00’ when rendering template ‘{{ strptime( state_attr(‘timer.wake_window_timer’, ‘finishes_at’), ‘%Y-%m-%dT%H:%M:%S+01:00’ ) }}’ but no default was specified

Again so sorry for the pain. cheers

I still think you’re not understanding what’s going on here, and I’m not clear what the actual problem or request is.

Firstly, strptime reads in a string and turns it into a datetime object. The format (all that %Y- stuff) tells it what the bits in the string mean. Your finishes_at attribute is as follows, and I’ve laid out the format below it, spaced out for clarity:

Attribute: 2023 - 05 - 05 T 13 : 49 : 05 +00:00
Format:     %Y  - %m - %d T %H : %M : %S +00:00

So strptime reads in 2023 for the year, 05 for the month and so on. Everything that isn’t a %_ format specifier must match exactly: the hyphens, the T and the +00:00 timezone at the end. If you change that timezone marker, it no longer matches what it’s being fed and throws an error.

To be clear: the attribute time is 13:49 in UTC / GMT time (+00:00), which is 14:49 in current local UK time (+01:00). As I understand it, that time is correct but you want to display it in UK timezone.

I’ve just created a test timer, started at 12:35 BST for two hours.

Those templates are:

{{ state_attr('timer.test_timer','finishes_at') }}
{{ state_attr('timer.test_timer','finishes_at')|as_timestamp|timestamp_custom('%H:%M') }}

Does that give you what you want?

Reference for most of this:

1 Like

Mate! Thank you so much for the extra details and in depth advise, that has indeed worked a treat and can’t thank you enough for all your time and effort. Hope you have an amazing day and thanks again. Cheers

For anyone else this was my final output thanks @Troon for being a legend and putting up with my noobness.

service: notify.mobile_app_pixel
data:
  message: >-
    {{
    state_attr('timer.wake_window_timer','finishes_at')|as_timestamp|timestamp_custom('%H:%M')
    }}
1 Like

Time is never a simple subject:

1 Like

That is truly accurate! What I thought was “straightforward” snowballed real quick. Thanks to the timelord that be you :slight_smile: