Hi all, I’m trying to think through a way to get an odometer style meter for lifetime usage of a UV light bulb.
Most of the suggestions involve changing HA to store data longer for states, but the UV bulb is expected to last 14 months of runtime and then needs replaced. I know I can use history-stats to get the ON runtime of the UV light from my switch sensor, but what is the best way to take this value and store it or add it to a running total sensor/counter to have lifetime value?
I was thinking, I could have an automation at 11:59 run and update the hours total on another sensor. Should this be an input_number or can I use a counter? Should I just setup an automation to trigger a counter to step increment when its been on for 1 hour and somehow loop it?
Example value at the end of a day.
value: 7h 28m
unit_of_measurement: h
friendly_name: Red Sea Aqua UV Runtime Today
icon: 'mdi:chart-line'
I have a similar situation where I want to count the total amount of runtime hours a vacuum tube has been energized.
I used your method and it seems to kind of work, but the total amount of hours is ridiculous: 477.660:07 which calculates to 54 years or so
I have exactly the same thing going on (tracking usage of a UV-bulb for water sterilization that needs to be replaced after 365 days of use), but even though you all have made great examples of how to do this I am stuck. I’m a total noob when it comes to programming, so please bare with me. I added this to the end my configuration.yaml, since that is apparently where these kinda things go (?) :
I ended up doing mine a little differently. I have a state I save as an input_number and then use an automation to increment it based on the amount of usage in the given day.
I dont have a Shelly so I am not show the format of their numbers but my sensor I had to setup formatting to get the times. My whole config is on github in case it helps.
@santaklon , which solution did you land on? I have a UV light I use for my swimming pool. The light comes on together with the filter/circulation pump and the running hours each day varies with the actual pool temperature. Therefore it would be good to monitor actual running hours and how many hours are left on the UV light bulb
In my case the UV-Lamp (together with the chlorinator) are on 24/7 when the house is inhabited, so its somewhat easy to keep track of the usage for now. But I would still like a solution for this. The provided ideas might work, but I’m really not a programmer and while I tried copy-pasting these lines into my config.yaml, I dont understand the code enought to adapt it to my installation / make it work.
I tried building something with NodeRed, but that seems unsuitable because it restarts counters whenever its is deployed.
Btw.: I was told the warm-up of the lamp when switched on takes quite a toll on the lifespan. So on one hand one should not switch it on/of too often but rather just keep it on and also I’m wondering if this would have to be somehow integrated in the counter…
Please bear with me once again, as I am a complete YAML / coding-noob and anything beyond click-pointy-UI is beyond my brain capacity.
So I have tried recreating your set-up. Not for the UV-Lamp (since its maintenance-cycle is a bit long for testing) but first for a pellet-burner that needs cleaning about every 30 hours of burn-time.
Some of the enities do show up as expected (but the equivalent of your “source” and um_water_uv_uv_running" does not) but no change can be seen when the burner is on.
Admittedly even after studying your code I have no clue what it all is doing since I am no coder myself. I just have just changed the names and entities.
Package:
(The entity sensor.pellet_heating_status is a templatet sensor i created from the power readings of the burner that does reliably report “burning” when it is in fact burning)
After adding the Automation HA threw an error message, that it doesn’t know “utility_meter”. Figured out thats an integration and installed it. I tried to create a matching utility meter but have no clue how to configure that part either, since it seems for tracking e.g. energy, but not time.
Also did not quite figure out what your sensors actually represent / what the numbers would tell me and how to translate them to my example:
Any help is greatly appreciated.
Thank you in advance!