[SOLVED] Convert seconds in mm:ss

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

  - platform: template
    sensors:
      count_d:
        value_template: >-
          {% set s = states('sensor.countd')|int %}
          {{ s | timestamp_custom("%M:%S") }}
4 Likes

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

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.

Thanks.

Works like a charm!!!

It work for me ! Thanks