Unexpected riemann integration results

I am using the following integration template to generate a power chart from an energy sensor:

sensor:
  - name: Battery Energy (Sungather)
    platform: integration
    source: sensor.inverter_battery_power
    unit_time: h

sensor.inverter_battery_power is an MQTT entity, which appears to be functioning correctly. However, the integration values are hugely negative and trending downwards over time. Here is a statistics graph of both:

batterypower

My understanding of calculus is very rusty, but my intuition is that this is not working correctly.

The inverter power appears to be going negative. There is no such thing as negative power.

That appears to be working.

However you may be seeing a lot of accumulated errors because you are using an inappropriate integration method. Try left, instead of the default trapezoidal.

In this case, negative values indicate power going into the battery (ie, it is being charged). I have separate template sensors that splits it into two different sensors for the Energy dashboard.

Thanks. I’ll give that a try.