The recently introduced (0.87.0) Integration Sensor is a great idea but needs a reset service to reset the integration in say an hour to calculate kWh from a kW sensor over an hour period.
The reset would be done in an automation service call.
Please see the Counter component for an implementation example.
Apparently, sensors cannot have services. The Counter component has its own domain so it can have a reset service.
For a brute force approach one could try calling a Python Script as a service, containing this one line: hass.states.set(sensor.your_sensor_name, 0)
I second this request (or appropriate workaround).
Although the Utility meter component does a great job of taking care of the time of segmentation mentioned above, my problem is somewhat different. I created the integration sensor with no prefix (like “k”) this gave me calculations in wh, which I later changed… this resulted in the figure remaining, but now calculated in kwh. would basically like to reset it once of… I guess I could just delete and recreate them, but there are some dependencies already, and I’d rather check if there are no alternatives.
My workaround was an automation that calls a python script. It is the ultimate way to get exactly what you want. You can reset the integration and change the unit of measurement. I combined the Integration Sensor and the Utility Meter in this example.
but with this I can only track one energy value.
If I would like to know solar energy produced, EV charged energy, total house consumption Utility meter is not usable, right?
I also vote for this request to have an option to reset the Integration sensor. I use the Integration component to total the rainfall per day. I use the yr_precipitation sensor, which measures rainfall in mm/h. (and often registers rainfall as 0.1 or 0.2 mm/h). The integration sensor works very well, and it would be very elegant if it could be reset to 0 by an automation at the end of a 24 hour period. I have now also tried the Utility Meter component, but it seems to me it is not set-up to total these small numbers (does it only work with integers and not with float?) and I get different totals compared with the Integration sensor.
Have you tried my workaround using a Python script?
Use an input number entity as an accumulator the reset it with something like: hass.states.set(input_number_energy_acum, 0, {"unit_of_measurement": energy_unit})
It works well but requires a little Python knowledge and an good example.
I fully agree with you, however I recently tried to solve this issue (still happening in 2022) for a water meter that gives one pulse per litre, now I was fiddling around with integration sensor and utility meter, tried statistics too, nothing really accomplishing what could have been. Finally I got the idea to treat the input as a binary sensor, in that case we can count the amount of times it turned ‘on’ which in my case corresponds to one litre. The history stats integration actually does a great job of counting the amount of on times and can easily be reset every hour, day, month. I also use the history stats to show the total usage over the past 24 hours.
esp32 code:
maybe this’ll help someone, I also know this won’t be useful for sensors that don’t use a pulse per unit used but the utility sensor really should be able to have handled this and integration too but here we are using binary sensor and history stats
Would also be great to have an option to integrate over a sliding window of time. I’m trying to integrate from a rain-intensity sensor to determine if I should close the windows or not. I don’t wan to close if I get a single spike at “3”, but I do if I get a bunch of densely packed "2"s…
For seeing the rainfall in the past minutes (or whatever time interval), you could also check out the statistics module and use something like the average value for a time window.
This is what I’m doing to (sort of) have an integration sensor reset to zero at midnight:
[Psuedo Code]
I have a sensor say sensor.Power
I use an integration helper (reimann integral left) to create sensor.EnergyTotal from sensor.Power
Then at midnight I set sensor.Midnight to sensor.EnergyTotal
Then I create sensor.EnergyToday to (sensor.EnergyTotal - sensor.Midnight)
Does that make sense?
You let the integration grow continually but capture its value at midnight and then calculate how much it has increased since midnight.
Hope it helps (clearly an ability to reset an integration sensor to zero at midnight would be much simpler)