Time Difference and UTC

Hi,

I want to create a template to calculate the time, my washing mashine needs to be finished.
The washing mashine does have an entity sensor.waschmaschine_washer_completion_time containing the local time when it will be finished as a string.

Ultimately I want to display the time in the format x hours y minutes (1h 29m).
My first thought was to calculate the difference of the timestamp from the mashine and the local timestamp. After reading the documentation and in this forum, timestamp always return UTC time, so i wanted to substract datetime objects.
Therefore i converted the string to datetime object and tried the following code in the developer environment. now() and utcnow() deliver the expected values, but after the substraction i get the same difference.
Where am I wrong?

Time local = {{ now() }}
Time UTC = {{ utcnow() }}

Time Washing Mashine {{ (states('sensor.waschmaschine_washer_completion_time')) }}

Difference local = {{ now() - (states('sensor.waschmaschine_washer_completion_time')|as_datetime) }}
Difference UTC = {{ utcnow() - (states('sensor.waschmaschine_washer_completion_time')|as_datetime) }}

with the code above I get the following results:

Time local = 2023-08-04 23:35:00.283173+02:00
Time UTC = 2023-08-04 21:35:00.283197+00:00

Time Washing Mashine 2023-08-04T15:23:50+00:00

Difference local = 6:11:10.283217
Difference UTC = 6:11:10.283233

Can you clarify your question?

Yes.

Imagine you called your friend down the street and your friend in England and asked them both “How long until it’s 10pm here?”… should they give you different answers?

There are a couple custom Macros for dealing with durations and relative times that you may want to take a look at:

or you can do it with something like this, but you’ll need to change the template to get the units and format you prefer.