Sorry this is a bit long winded, please read all of it and give the code a go
Background
I have been working on some new code to provide auto scaling for the totals as the bottom of the SolarPV screen. It automatically formats the data using 3 digits and adjusts the Units to stop the amounts from getting so big that they wreck the formatting by sliding onto a new line on small displays like mobile phones.
To test the new code boundary conditions (W->kW->MW) I have been using the zoom to get the right magnitude of data from my existing solar system. If I zoom out the figures get bigger. I can get into kWh during a single day but have to zoom out a long way to get into MWh (over a year)
I have a smets-II smart meter and a solar generation meter. I use them to maintain a spreadsheet of monthly power usage. So I know what the annual figures should be. The Emoncms kwh feeds agree with the spreadsheet totals and meters within a few percent. My power usage and generation is fairly stable year to year. 2024 is a noticeably bad year for solar generation. I only have one 300W solar panel.
There are no hole or zigzags in the kwh feeds, I checked that first. Thanks for the fix a while ago, I had the restart issue.
Issue
If I zoom out to 1 year then the power usage and import figures are nearly 10% low
If I zoom out to 2 years then the totals should be twice as big, they are not and the errors are even larger
Zoom out 6 years and the power usage and import are nearly 50% low, the reported solar generation drops to 15kWh which is 0.8% of the physical meter reading
The inconsistencies are pretty bad once the zoom exceeds a month with my data and minor but detectable at week level
I think its caused by sampling spiky data with too long an interval
Investigationg the problem
I found a stub section in mysolarpv.php starting with
// Consider loading totals from kWh feeds if available
and decided to replace that with some code to display the kwh feeds via console.log They could then be compared with the figures calulated from the raw data and displayed by the App. I used Chrome developer to display the app and show the kwh derived data alongside it
// Consider loading totals from kWh feeds if available
// Need to avoid too many requests here, currently updating every 10s
skwh = get_kwh_between_two_timestamps('solar_kwh',view.start*0.001,view.end*0.001);
ukwh = get_kwh_between_two_timestamps('use_kwh',view.start*0.001,view.end*0.001);
ikwh = get_kwh_between_two_timestamps('import_kwh',view.start*0.001,view.end*0.001);
dkwh = ukwh - ikwh
ekwh = skwh - dkwh
console.log("-- "+Math.round(t*100/(3600*24))/100+' day(s) from kWh feeds');
dp = Math.round(dkwh*100/ukwh)
ep = Math.round(ekwh*100/skwh)
ip = Math.round(ikwh*100/ukwh)
console.log("Use "+Math.round(ukwh*100)/100);
console.log("Solar "+Math.round(skwh*100)/100);
console.log("Direct "+dp+"% "+Math.round(dkwh*10)/10);
console.log("Export "+ep+"% "+Math.round(ekwh*10)/10);
console.log("Grid "+ip+"% "+Math.round(ikwh*10)/10);
Possible solution
I then added some code to to use the kwh feeds instead to drive the mysolarPV App. It only activates when you zoom out to show more than a month. This is an arbitrary figure, comments welcome
The original code that does this work remains to collect the data for drawing the graph. The totals are just overwritten
Add this directly after the previous code
if (t>3600*24*30) { // over 30 days
//console.log("Using kWh feeds")
if (typeof skwh !== 'undefined') total_solar_kwh = skwh
if (typeof ukwh !== 'undefined') total_use_kwh = ukwh
if (typeof dkwh !== 'undefined') total_use_direct_kwh = dkwh
}
I could turn this into a pull request after its been tidied up a little and a decision made about the threshold to activate it