Energy integral sensor giving false values

I have setup a sensor that monitors my wallcharger for my EV. What I do is a multistage setup that I will explain first:
The first sensor is a binary one that will switch on as soon as the sensor.p1_meter_active_power is above 9800W and will switch of when below.

entity_id: sensor.p1_meter_active_power
hysteresis: 0
lower: null
position: above
sensor_value: 11241
type: upper
upper: 9800
device_class: battery_charging
icon: mdi:ev-station
friendly_name: Ratio Solar Active

Next I have a sensor that copies the sensor.p1_meter_active_power as long as the switch is active ( I use a factor 0.95 to compensate for other energy consumption):

  - sensor:
      - name: Ratio Solar
        unique_id: sensor.ratio_solar_power
        icon: "mdi:ev-station"
        unit_of_measurement: "W"
        device_class: power
        state_class: total
        state: >
          {% if states.binary_sensor.ratio_solar_active.state == 'on' %}
            {{ (0.95 * states("sensor.p1_meter_active_power")|float) }}
          {% else %}
            0
          {% endif %}

Finally I have created an integral sensor that uses the previous to get the energy. It uses the Trapezoidal rule, with a 2 digit precision and measures in Wh. Its history graph shows this:

The graph for both the P1 and the wallcharger (Ratio Solar) show this:

However the energy dashboard shows a positive value of 680.22kWh for the Ratio Solar Energy sensor and a -672.86kWh of untracked energy:

The value of 7.36kWh is the correct power consumption of the wall charger. What am I doing wrong here? These extreme values only occur at the start of the charge.

You show everything, except the important one: the integral sensor. Make sure you use left riemann, especially if you have sensors that go to 0 for long periods of time. Because Home Assistant does not store values if values do not change, what happens is that the default, trapezoid, assumes a gradual increase in value from the last time it went to 0 up to the first measurement that you get, leading to a big triangular area it suddenly counts as usage.
IMG_0923

On a sidenote, not this problem but maybe others: use availability templates to indicate when sensors are not available. this too can prevent headaches.

Thank you for the reply.
I’ve updated the integral sensor to left riemann. Next charging session I’ll check if it’ll solve my issue.

1 Like