Progress in Percentage

I have the following two sensors from my washing machine

  • sensor.washing_maschine_initial_time outputting the expected overall duration of the programme at the start
  • sensor.washing_maschine_remaining_time outputting the permanently updated duration until end of programme

and would like to get the progress expressed in percentage (i.e. parts / whole * 100 ) in order to display the progress of the washing machine programme on a mushroom chip card (see here)
Both sensors provide a string in the following format 0:00:00 (i.e. h:mm:ss)

The following template fails to calculate the progress:
{{ (states('sensor.waschmaschine_remaining_time') / states('sensor.waschmaschine_initial_time') | float * 100) | round(0) }}

So somehow I need to extract the from each of the sensor the hour and minute value (i.e. %H*60 + %M) in order to compare it to the other sensor. How can this be achieved?

First, I see you also opened this in discord, which is not prohibited of course but also makes me hesitate to spend time where others do so as well…this is not life threatening so might be patient?
What value is your remaining time sensor kicking back, did you create that yourselves and then how?
Edit: I see the values but did you create it as then it might be better to create something else so it can be used in multiple areas

Edit 2:
try this in devtools > template (use your sensor instead of the hardcode value)

{{ ('01:02:03').split(':')[0] }}
{{ ('01:02:03').split(':')[1] }}
{{ ('01:02:03').split(':')[2] }}
{{ ('01:02:03').split(':')[0] | int }}
{{ ('01:02:03').split(':')[1] | int }}
{{ ('01:02:03').split(':')[2] | int }}
1 Like

Thanks for yout time. Yes, I have put in a similar question on discord and also searched the forum for a solution and thought it may be documented in a better way using the forum. Sorry for the redundancy.
The sensors are provided by the LG ThinQ Integration.

So… did it help my suggestion above?

{% set h1,m1,s1 = states('sensor.waschmaschine_initial_time').split(":")|map('int')|list %}
{% set h2,m2,s2 = states('sensor.waschmaschine_remaining_time').split(":")|map('int')|list %}
{{ ((h2*3600+m2*60+s2)*100/(h1*3600+m1*60+s1))|round(0) }}

Or you could convert each to a timestamp with strptime. Templating - Home Assistant

1 Like

Yes, thank you very much. Appreciate your support.
I have it down to the following template now, which does provide the expected percentage, when the initial time is set (i.e. when the washing machine is running).

{{ ((( states('sensor.waschmaschine_remaining_time').split(':')[0] | int * 60 ) + 
     states('sensor.waschmaschine_remaining_time').split(':')[1] | int ) / 
   (( states('sensor.waschmaschine_initial_time').split(':')[0] | int * 60 ) + 
     states('sensor.waschmaschine_initial_time').split(':')[1] | int ) | float * 100) | round(0) }}

If the machine is not running the output is 0:00:00 and therefore I have a division by zero, which I need to filter out.

{% set d = states('sensor.waschmaschine_initial_time') | as_timedelta %}
{% set t = states('sensor.waschmaschine_remaining_time') | as_timedelta %}
{{ (t / d * 100) | round (0) if d != as_timedelta(0) else 0 }}

EDIT

Simplified it.

2 Likes

Thanks, seem to be so many ways to get the result.
This one seems quite elegant. The division by zero may not really be an issue, as the chip card is only displayed, when the machine is running. At this point in time the sensor.waschmaschine_initial_time should not be set to 0:00:00.