Add Leading Zeros to numbers?

Of course. My example was just a cut and paste from a real sensor I have, where the output is more complex than just (days) hours minutes - and it is in Norwegian, not English, so the sentence is not quite like in my example-code.

There is always a balance between keeping it short and keeping it readable… So everyone will need to find how they want to do it. But it sould be great if timestamp_custom had a few more choices to make stuff like this even easier.

I think that we just have to expose time deltas. The format options we see in jinja come directly from pythons strftimes. Getting that changed will be a long shot. But there may be ways to extend the timestamp_customs formatting unless it just uses pythons strftime.

Sorry to “again” awake an old thread, you will think i’m dumb but i’m having headache trying to add “0” to my splitted time sensors:

  friendly_name: 'Time hour'
  icon_template: mdi:clock 
  value_template: >-
    {% set hour = states('sensor.time').split(':')[0] | int %}
    {{ hour }}

  friendly_name: 'Time minute'
  value_template: >-
    {% set minute = states('sensor.time').split(':')[1] | int %}
    {{ minute }}   

I have tried multiple codes but none of them works for me.

Any help would be very much appreciated


{{ '%0.2d'|format(minute) }}


Thanks @jazzyisj !

1 Like