Hi, I’m trying to get a grip on electric car usage and am struggling with Riemann Sum methods. Math has never been my strong suit.

What I understand is the Riemann sum tries to estimate the surface below a graph using a small amount of samples. In my example I want to know how much power went into my car based on the charging rate that my car provides. The Riemann method must be picked according to the behaviour of the input inbetween samples. If samples are close to another, the method is not that relevant, when samples are scarce it does matter a lot.

The way I understand Home Assistant is that it does not store values if the values stay the same. Also a lot of sensors try to save energy by either not send values when there is no change, or decrease the sample rate when there is little change. So basically, when using HA the Riemann sum method is vital to get right, because samples are almost always scarce if there’s little fluctuation.

In my example, when I put the car on a fast charger, trapezoid was way off because I hadn’t charged in a while, and then the charging current want way up. The Riemann sum using the default method assumed I charged 400kWh in a matter of seconds, based on a 50kW charger:

Here’s what I’m struggling with. When would it make more sense in Home assistant to pick trapeziodal (the default) over left? Because if I understand the methods correctly, then left is almost always the way to go if sensors only send values that are different from the value before?

To say it differently: the best representation of values from the recorder of Home assistant is a usually a block graph where thee line is constant until a new value comes in. Because if the value had changed before that, Home Assistant would likely have another measurement stored. It didn’t, so most likely the value was unchanged before.

Am I right that what a left Riemann sum does is the best fit for what the Home assistant recorder aims to store to save database space and what sensors do to save battery use? Is left right (pun intended)? And when would it be the wrong choice?

And a followup question: am I right that the derivative functions does basically the opposite of the Riemann Sum, and if so is there an equivalent for the method there to get the right derivative in the above situation? Because I get the feeling that that does not always work as intended either for similar reasons.