Calculate running time of washing machine - template sensor relative time but with HH:MM

I have an input select helper for my washing machine with two options: ‘done’ and ‘busy’. An automation checks the power consumption and sets the helper to ‘busy’ when the machine is on.

Now, I want to display the time in HH:MM format on my dashboard from the moment the washing machine’s input helper is set to ‘busy’.

Bonus question: I want this time display to appear on my dashboard only when the input select is ‘busy’. There’s no need to show the start time when it’s not running.

Currently, my template sensor is:
{{ relative_time(states.input_select.wasmachine_programma.last_changed) }}

This results in displays like ‘6 minutes’, ‘1 hour’, or ‘2 hours’ for 90+ minutes of running time.

I would prefer to see the actual time elapsed, not ‘1 hour’ but ‘1:32’, for example.

It seemed like a straightforward question and task, but I’ve been struggling with it for longer than I’d care to admit.

Thank you in advance.

Maybe there is a better method but here is one:

{{ ((now() - states.input_select.wasmachine_programma.last_changed) | regex_findall("\d+:\d+"))[0] }}

You can’t use regex on a timedelta object.

Odd, I still wouldn’t rely on that as findall doesn’t naturally turn objects into strings. I would consider that subject to change at any time. Especially seeing how most methods don’t do this and require a default value.

If that is the case then it’s an easy fix.

{{ ((now() - states.input_select.wasmachine_programma.last_changed) |string | regex_findall("\d+:\d+"))[0] }}

But according to developer tools the result is not an object but a string.

That’s the resolved type after the template has executed, not the actual object type during jinja execution.

thanks for your input.
I now have a counter that counts up with HH:MM.
now for the second part of this quest, i want it only to count if the machine going from status ‘done’ to ‘busy’. when last_changes is from busy to done there is no need to count. is that possible?

I suppose you could do like this:

{%- if states('input_select.wasmachine_programma') == "busy" -%}
  {{ ((now() - states.input_select.wasmachine_programma.last_changed) |string | regex_findall("\d+:\d+"))[0] }}
{%- endif -%}

This should leave it blank if the select is not in busy mode