Update Frequency of Riemann Integrator


since quite a while I am using the riemann integrator to derive kWh from Watts. It is a common topic. Today I looked a bit surprised into my HA, as it repoted 100% self-usage of energy despite showing powerflow into the grid. Upon additional investigation I noticed that the energy put into the grid was reported larger than the produced energy, which obsiously cannot be.

This is the riemann integrator to derive the energy-flow into the grid (unused energy):

Two things seem non-nominal to me:

  1. The update rate of the integrator is in the order of 15 minutes, however it should update whenever the source (above curve) updates.
  2. The integrator spikes upon the first value greater zero.

Sadly I cannot check the integrator configuration, as it is a known limitation of the options presented in lovelace after creation, so I will now create a new integrator with prefix k, integration duration h and method left (recommended settings as far as I can see).

Any comment to this strange behavior is appreciated.


Definitely an issue with not selecting method: left instead of the default trapezoidal.

1 Like

I recreated the integrator with method left last night, but the result today wasn’t much better:

Integrator details:

Remove the prefix and duration options from your Riemann Sum config and see what happens.

But yeah I agree that does not look good.

It is very spikey data. Are you sure this is the power output of your PV array and not a silly metric like “instantaneous” energy per minute that some devices report?

I would expect to see something more like this for the PV power output:

The curve shows the power going into the grid. From a logical viewpoint this depends on the produced PV power and the power demand. From an implementation viewpoint, it is a template sensor checking the smart meter and whenever negative, it just reports the absolute value. Hence the “noisy” data, which essentially reflects the power demand niose. Obviously the curve can only report values greater zero if the sun is actually shining.

I think I found an explanation for this. I increased the integration accuracy to 6 digits. The result is that I can confirm in a simple template that the integrator is updated whenever the source changes. However by limiting the integration accuracy to only two digits I simply only notice changes when the second digit changes. In the picture above with the left method this can be clearly seen. It starts with .860 and after some time it reaches the .870.
In summary it is thus my expectation which was wrong. A smooth curve would simply require more significant digits. I was just surprised to see this now, as I remembered it working in summer time - which now also makes sense, since with higher input power levels the second digit changes much more rapidly…

1 Like