I have two time sensors for my dishwasher (start and finish). I want to subtract “start” from “finish” to get the total duration (in minutes) for the program. Unfortunately this is not delivered by the integration. Attention: the value can also be “unknown” when no program is running.
Then I want to divide the “remaining time” by the created “duration” to get the %-value. I want to use this value for an automation related to WLED (status progress bar).
I’m pretty new to HA and already stuck at the first challenge “calculate the duration if state is not unknown”.
Can you please assist me?
I use this format under developer tools, template: {{ (today_at(states('sensor.dishwasher_finish_at')) - as_timedelta(states('sensor.dishwasher_started_at'))).timestamp() }}
It responses a really high number when the program is running. It responds ValueError: could not convert str to datetime: 'unknown'
if no program is running.
So first at all I want to have a “if else” connection to avoid errors.
That’s the easier part, before we go there we need to know what formats we will be dealing with.
When the dishwasher is running what do the state values of dishwasher_started_at and dishwasher_finish_at look like?
For the “remaining time” sensor, how do you want the state presented? The screen shot posted above notes the unit of measurement is minutes… should that be whole minutes only or fractional minutes?
That is likely because you are using at least one incorrect time manipulation function for the inputs you have or the outputs you want. There are many functions related to time and time math, making it very easy to tie yourself in knots if you don’t have a clear understanding of where you are starting and what your goal is.
Thanks will check tomorrow when the dishwasher is running.
Remaining time is a sensor which is provided by the add on and shows the time left. I will also check which format is provided.
Oh wow. Thank you very much but the response is the same time ans the finish time (dishwasher is running). Attached the screenshot of the entities. Maybe the problem is the entity of “remaining time” wich is given in min. But the calculation responses with hh:mm?
Now it’s getting suspicious. I am getting the result “0” which means, that “unknown” was detected. It doesn’t make sense because there was no “unknown” state.
No, the other configuration variables are optional… If for some reason you wanted to keep long term statistics, you would need to set State class to measurement.