Convert Time

Hi,

New to home assistant and trying to figure out how I can convert a sensor with 5:34:34 ( hours:minutes:seconds ) to something like 5h 34m as it looks cleaner and nicer in the UI.

I have tried many ways but none seems to work. Any help would be appreciated. :grinning:

Thank You!

1 Like

Can you maybe show me how?

Thanks!

Put this into the Template Editor and experiment with it:

{% set x = '5:34:34'.split(':') %}

{{x[0]}}h {{x[1]}}m

If the sensor you have is called sensor.timestring then:

{% set x = states('sensor.timestring').split(':') %}

{{x[0]}}h {{x[1]}}m
1 Like

I was hoping you would pop along!

Thanks!

{% set x = states('sensor.timestring').split(':') %}

{{x[0]}}h {{x[1]}}m

Works great for me, thanks everyone for helping! :heart: