Problem converting seconds into H:M:S

Hi there.
I am using the following code…

{{states(‘sensor.anova_precision_cooker_cook_time_remaining’) | int(0) | timestamp_custom(‘%H:%M:%S’) }} Remaining

…to convert seconds to an Hour, Minute, Seconds format.

However, with the input 2149 I get 1:35:49 when it should be 0:35:49.

Any idea what I’m doing wrong?

Thanks in advance!
Dan

I’m not a guru in this, so I expect something better, but this works I think

{{ (states(‘sensor.anova_precision_cooker_cook_time_remaining’) | int | as_datetime).time() }}

What you are doing is converting a timestamp (the number of seconds after midnight 1st of January 1970 in the UTC timezone) to a datetime, and then you format it using the settings provided.

So you are saying I want the time in the H:M:S format of 1st of January 1970 00:35:49 UTC.
However, by default timestamp_custom will convert this to your local timezone which apparantly is +1
So it will give you the time in H:M:S of 1st of January 1970 01:35:49 GMT +1.

To disable this conversion to local time, you need to add false to the timestamp_custom filter.

{{states('sensor.anova_precision_cooker_cook_time_remaining') | int(0) | timestamp_custom('%H:%M:%S', false) }} will give you the expected result.

3 Likes

in addition to thefes’s response, you can just use
{{ timedelta(0, states('sensor.anova_precision_cooker_cook_time_remaining') | int(0)) }}

3 Likes

Thanks - both those answers did the trick, and I’ve learned something new. Nice! :smiley:

Ah, nice one, it will also show days in case you have a very long timer on you cooker :wink: