So I did a node-red solution that integrates with a input_number helper. (@Hellis81 thats the other post you have been responding too)
I do everything else in node red, so I wanted to keep this in there too. I didnt think it was possible, which is why I originally made the post. But then found there is a way.
FWIW, I use a History Stats sensor to compute daily run time (for heating, cooling, etc) combined with the Utility Meter integration to keep a running tally of daily/weekly/monthly/yearly data.
The Utility Meter integration records its data in long-term storage (statistics table) and is unaffected by the recorder’s purge cycles.
Hi, please could you tell me how to create a status counter when an entity is in the “on” state and that is not cut by the recorder? I haven’t found a solution yet.
Ah! That topic seems to be a complicated one for HA!
I’ve just spent the last 6 hours trying to wrap my head around a simple elapsed timer in HA for my car charger. It doesn’t exist.
I found a Stopwatch with start/stop/resume, lap and reset solution which uses 4 input_booleans + 2 template triggers + 3 automations, 1 of which runs every second. I did not like that approach either…too much work plus I do not like the idea of an automation firing once every second. There is this solution using input_datetime helpers but you need automation(s) to update the datetime helpers. I moved from HomeSeer over a year ago and it has had timers for many, MANY years where you can create timers which can count UPWARDS unlike HA timers which only count DOWN from a DURATION.
So I had a look over in Node-RED and started searching there. Also somewhat void but I did mange to find a node that I have made work: the interval-length node…
You need two input_datetime helpers, one to store the start time and one for the stop time. Then an automation that fires when the device turns on which updates the start time helper and another automation that fires when the device turns off which updates the stop time. I combined the two automations into one with two triggers and a choose section. Last item is a template sensor whose state is ( end_time minus start_time ) if the timer is stopped, or ( now() - start_time ) if the timer is running. I threw the following together this evening. In the code below I’m using an input_boolean that I created to trigger & test it. Just replace the input_boolean with the entity_id of the switch you want to track.
I posted a solution a year ago (see above). Use a History Stats sensor and the Utility integration.
I’ve used the combination for well over a year and have daily, weekly, monthly, and yearly stats for how long the furnace has been heating and the AC has been cooling.
Trying it, unfortunately, the sensor is not working every time the entity changes state from “INATTIVA” to “IN FUNZIONE” it resets and starts again with zero value.
I started recording long-term statistics for a fan in October 2021. Here’s its yearly Utility Meter sensor data. You can see it has data for 2022 and 2021.
If you set the sensor’s cycle to yearly it will display the total of the current year’s data (even though data is recorded for all years and can be graphed as I demonstrated in my previous posts).
According to the documentation, cycle is optional so you can try creating a Utility Meter sensor without the cycle option and, in theory, it should simply display a running total indefinitely. I say “in theory” because I have never tried it (because I don’t need to display a running total that spans multiple years).
The cycle option is just a way to tell the sensor the time span it should use to calculate its result. It gets the total of every day from the History Stats sensor and uses that to compute a total for day/week/month/year based on what’s specified for cycle.