Help with integration sensor

I am reading these graphs:

Where:

  • the one at the top is the power (Watt) used by the garden lights
  • the one at the bottom is the integration sensor to get the energy (kWh)

The lights were on at midnight and turned off at 6 am. In the energy graph, I see the value raise at 6am and that’s fine.
Then, the lights turned on again tonight at 20:44. You see that in the power graph. But I am really not able to understand why, at the same time, the energy sensor rises, like there was consumption between 6am and 20:44 (while the power sensor reading was 0 the whole period of time!).

This is the configuration part for those sensors:

- platform: template
  sensors:
    lampadine_giardino_power:
      friendly_name: "Lampadine giardino power"
      unit_of_measurement: 'W'
      value_template: >
        {% if is_state('light.p3', 'unavailable') %}
          0
        {% elif is_state('light.p3', 'on') %}
          33
        {% else %}
          6
        {% endif %}

- platform: integration
  source: sensor.lampadine_giardino_power
  name: lampadine_giardino_energy

And this customization:

sensor.lampadine_giardino_energy:
  friendly_name: Consumo lampadine giardino
  unit_of_measurement: Wh
  device_class: energy

I think the integration sensor shouldn’t have such a rise at 20:44. What am I missing here?

You may need to change the method used by the Integration Sensor. The default is trapezoidal and, because of how your light consumes power, you may need to change it to left.

method string (Optional, default: trapezoidal)

Riemann sum method to be used. Available methods are trapezoidal, left and right.

Note the comment in the documentation:

In case you have an appliance which produces spikey consumption (like an on/off electrical boiler) you should opt for the left method to get accurate readings.

Th Integration Sensor computes its value when the light’s power changes. That exactly what happened at 06:00 when the power value changed (and decreased to zero).

From the documentation:

The integration sensors is updated upon changes of the source.

Thanks @123 ,
at 8:30am I changed the integration to method=left and now I got a more reasonable output:

My bad, I thougth that “left” was default.
But still it’s not clear why left is suggested for something that produces spikes of consumption, while it’s pretty clear that is better in my case where the consumption is quite “flat”.
Thanks again!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It will help users find answers to similar questions (especially since Energy management was recently added to Home Assistant).