I have solar and using an external docker sending MQTT i get the current active energy imported from the grid whilst the MQTT integration does keep a record of Energy Imported from Grid in kWh this gets reset if the docker container is restarted for what ever reason. Hence i am trying to use a Reimann Sum Integral to get the energy using the current power imported from the grid in Watts.

This works when i get continuous readings e.g. overnight when there is no solar BUT during the day if there is a sudden spike in import (when there is a cloud for example) then the Integral has a large increase:

The blue line is the Reimann integral sum (daily using a utility meter) and purple is from the external docker MQTT inputs which works as expected.

This is the graph of Watts imported which has the spikes shown:

Does anyone else see this? Is this just a mathematical limitation or is there some defect here?

My Reimann integral is over 1 hour and in kilo.