Hi
how can I convert seconds in mm:ss?
I tried several templates found around here, but none works for me.
- platform: template
sensors:
count_d:
value_template: >-
{% set s = states('sensor.countd')|int %}
{{ '%02d:%02d' % ((s%3600)/60), (s % 60 ) }}
What is the correct template?
Thanks
Hellis81
(Hellis81)
August 3, 2022, 11:35am
2
- platform: template
sensors:
count_d:
value_template: >-
{% set s = states('sensor.countd')|int %}
{{ s | timestamp_custom("%M:%S") }}
4 Likes
123
(Taras)
August 3, 2022, 11:36am
3
Use the timestamp_custom
filter.
Copy-paste the following into the Template Editor and experiment with it. This particular example converts 630 seconds into 10:30
.
{{ 630 | timestamp_custom('%M:%S', false) }}
Oops! Ninja’d by Hellis81
5 Likes
Hellis81
(Hellis81)
August 3, 2022, 11:40am
4
Sorry!
Didn’t see you were typing.
But the local setting isn’t needed unless you live in a odd timezone that has 30 minutes or 45 minutes offset from GMT since the hours are out of bounds in mm:ss.
But it does not matter, it doesn’t hurt to have the false there.