Hi everybody,
I have found some great tips on these forums trying to work with timestamps and time formats, but I cannot get this to work. Tempered with it for a couple of days now, but never get the result I want.
There is history_stats
, which might be able to do what I need, but either I cannot configure it correctly, or it is just not meant for this.
use case
We have one single vacuum
entity for two floors in the house. It is a Neato Botvac D7
, which can be integrated in Home Assistant without any issues. Due to the fact that it needs to run (at least) twice per day (=once per floor), we need to manually carry it up the stairs once the ground floor is done.
It would be nice to have an overview about how long the current cleaning cycle has been so far, so that we can estimate how much longer it is going to take. Times vary depending on if it actually cleans all rooms, or of some doors are shut…
attempts
So I tried to write now()
to an input_datetime
(has_time: true, has_date: false
) when the device’s status changes from anything other than cleaning
to cleaning
. I then have an automation that will run every 2 minutes (time_pattern
), checks as condition
whether the state of the entity is still cleaning
, then it is supposed to write a value that is now() - <start_time>
to another input_datetime
.
I have tested countless templates in developer tools, but I just won’t receive the value I need. Let’s say I initiate cleaning at 12:34:20
and ten minutes pass; it is now 12:44:22
, and the input_datetime
entity ought to equal 00:10:00
. I have not posted my different approaches in order to not add extra confusion to this (but I can if anybody here thinks that it helps).
Basically, I am looking for the correct template that subtracts the start time of the vacuum (previously set via input_datetime
) from the current time / now()
.
I tried converting both to timestamps, then substract one from the other, then convert the result back to timestamp_custom
, but even though I sometimes do get values, there must be something wrong with the template, as it does not show the actual time that the robot has been vacuuming.
Considering history_stats
, it will display the correct time the robot has been vacuuming, but only the first time. I have not found a way to reset it back to zero, so the second time the vacuum starts cleaning, I get whatever the value had been previously plus the current vacuuming time. (I got the actual minutes by {{ states("sensor.cleaning_time") * 60 }}
, as the sensor reports something like 0.38 hours, which has to be converted).
What I need is a sensor displaying hours and minutes (seconds optional, as it is only updated every two minutes, anyway) starting when the vacuum entity switches to cleaning, and resets when it switches to it’s ready state… what do you suggest I do?
Thank you for your ideas