The riemann integral is used to calculate for example the energy comsumption from the current consumption. Or if a sensor delivers “liters per second”, the riemann

integral calculates “total liters”.

The riemann integral integration uses the trapezoidal method as the default calculation method for the area under a curve.

But in in many cases this default is wrong.

Assume the temperature curve of a heating radiator which is polled every 10 minutes. If it is 20° at time t and 30° at time t+5, you can

assume that the temperature went up slowly from 20 to 30°. So the area under the curve is (20+30)/2 * 5 min. (20+30)/2 is the average temperature.

But now let us look at a cooking plate. It is off for 10 hours and it is switched to 2kW now. HA did not get any sensor readings for 10 hours,

because the value did not change. So the energy is calculated as (0kW + 2kW)/2 * 10 hours = 10 kWh. So for the first second you switch your cooking plate on,

HA calculates 10 kWh energy comsumption. This happens with all devices where the comsumption remains at a constant level for a longer time and then goes up.

For these cases, you can use the method:left which calculates the area under the curve only as old-value*time.

So for values which are continuously differentiable, the trapzoid method is ok, for values which change in steps (i.e. for the most electrical appliances), you should

use method: left.

The problem is that most people do not think about that problem and they will get totally wrong readings for their energy consumption.

Solutions for this problem:

- make method: left the default
- enhance the documentation and warn
- introduce a new “method: optimal” which uses method:left if the elapsed_time is long or if dX/dY is big, i.e. the gradient is large. in all other cases use “method:trapezoidal”