How to keep track life left on something that runs out?

I have a mosquito repellent on a smart plug and I know the liquid lasts about 30 days (720 hours or 43200 minutes) before it’s empty and I have to replace it. It is turned on at different times depending on day or night, presence detection or if someone turns it on during the day because they notice mosquitoes in home. It sounds like it should be simple for home assistant to let me know before the liquid runs out so that I can replace it and I don’t have to wait until we are being bitten to realize.

Ideally I guess I would have some kind of count down timer that is started every time the smart plug is turned on and it is stopped when the smart plug is turned off. Then I would just have a notification sent to me when it reaches zero.

I just can’t figure out how to do it. Do you have any idea how this can be done?

Timer with “720:00:00” start and stop it with an automation according to the smartplug.

But might not be the most stable option, what happens when it can’t stop the timer due to some problem with HA or you restart HA etc… Not sure.

EDIT:
History Stats - Home Assistant might be another option, but you have to have history data from the plug of around 30 days as you said and you have to set the start value everytime you replace the liquid.

Or google for: “hassio keep track of on time” to find more solutions.

Thanks for the reply. You are right, I did some testing and it seems the timer is very unstable. It has already reset a couple of times without my intervention.

I will look into History Stats as you recommend. :+1: