I built an integration that allows to SUM up a sensor. It is a blatant copy of the integration sensor, but simpler. It does not create a riemann sum (integral) but a normal sum and is not dependent on time it just uses the round and prefix variables like the integration sensor.
I might have missed a better solution, but if not, you can solve it like me.
Why I did this? Well I have an ESP8266 attached to a sensor it gives me pulses. So when I have 1000 pulses in one hour I get a kwh. But I read this not every hour but every 30 seconds.
- I tried doing this with a template but it was very complicated and wrong.
- I tried an integration sensor but the values were always off by a lot, the problem is I’m reading my heater and when it starts it uses 1700 watt or even 2450 and then goes to 0 after some time it does it again. These hard steps were making the integral sum to be off by at least 20%.
- I tried the statistics sensor but it only allows for cycles with a maximum amount and it was also off by a lot.
- I tried the history sensor but that one just tells me how often my sensor does something and does not sum it.
My solution was just changing the integration sensor in a way to not use time as a factor and then just making a sum and not an integral calculation. I use that sum as my actual meter and it shows 100% the same number as the normal meter. I used that plainsum sensor for the utility meter. If you use ESPHome you might not need this. But i created my esp8266 with a plain c script and did not want the overhead.
So if you encounter the same problem you might want to give this a try. But as I said before, I might have just overseen a much simpler solution.