This might be an obvious task, but I cannot find the right answer; I have several sensors that report their energy usage every 8-30 second in watts. Now I want to transform that into kWh untill today and kWh since measuring began. Most probably this needs to be done using a template sensor, but I don’t have a clue where to begin. Formula probably needs to be (sum watts) X time in hours since midnight / 1000. And for the total since reading began (sum watts) X time in hours since reading began.
The energy E in kilowatt-hours (kWh) is equal to the power P in watts (W), times the time period t in hours (hr) divided by 1000: E(kWh) = P(W) × t(hr) / 1000
I had a look at your solution, but that won’t work. It will simply take the current usage and multiply that by 24. I believe I have to take the sum of all watt readings today and then multiply that times the amount of hours since midnight…
I was originally thinking you could use the mean over the last hour using the Statistics Sensor, but that’s not going to be very accurate because the samples are at irregular intervals. You’ll probably need to create a custom component that can do the necessary calculations.
Another option would be to send the data to EmonCMS/EmonPi to do the calculations.
Well… I already took that approach about a year ago, but since I upgraded my Raspberry pi to Raspbian Stretch (and updated to homeassistant 0.58) I keep on getting urrlib3 connection issues. That is why I want to move all to my local system.
I am currently thinking of using the average from the statistics sensor to calculate the kWh, but am a little bit low on spare time at this moment