Battery charged-energy < discharge-energy

Hello!
I’m wondering why the charged-energy in my battery is smaller than the discharged-energy. Normally it would / should be the other way round.

I’m using the following sensor to get the actual power from/to my battery:

  sensor:
    - name: "Batterie-Leistung"
      unique_id: batt_leistung_w
      state_topic: "N/48e7da86338e/battery/512/Dc/0/Power"
      value_template: "{{ value_json.value }}"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement

and the following template-sensors:

template:
  - sensor:
      - name: "Battery-Charge-Power"
        unique_id: batt_charge_power_w
        unit_of_measurement: "W"
        device_class: power
        state: >
          {% if states('sensor.batterie_leistung')|int > 0 %}
            {{ states('sensor.batterie_leistung')|int }}
          {% else %}
            0
          {% endif %}

      - name: "Battery-Discharge-Power"
        unique_id: batt_discharge_power_w
        unit_of_measurement: "W"
        device_class: power
        state: >
          {% if states('sensor.batterie_leistung')|int < 0 %}
            {{ (states('sensor.batterie_leistung')|int * -1) }}
          {% else %}
            0
          {% endif %}      

with this power-sensors i’m integrating the energy from the power via helpers
(here i wanted to add more screenshots which unfortunately is not allowed for new users. I’ll try to add them next…)

Any hints why the discharged energy is computed to a greater value than the charged energy ???

Ove

Battery-Energy-Helper:

i started the computing of battery-energy ~ 4 weeks ago

from day to day the “discharged” energy grows bigger / faster than the charged energy…
battery-SoC every day starts from 20% in the morning and ends with 20% at evening/night

having a look at the energy “discharged” today i see a jump from 3kWh in 1min - which is definitely an error:

May “left rieman” integration be better than “trapezoid” ?

with “left riemann” it looks smoother: