Utility meter for my battery reading (i have only a positive power and a negative power reading

I Have a Growatt inverter connected with Esphome where i read all values that i could find.
I like to see the daily , monthly and all time charge and discharge value so i can integrate these in the Utility meter.
The problem is that i only can read a battery power positive and negative value.
when the battery power value is negative it is charging, when its positive the battery is discharging.
Any help with this would be much appreciated.

Feed that power sensor to the Riemann Sum helper to get energy. The battery stored energy will increase when it is positive and decrease when negative.

Be sure to read the section on “method”. You probably want left.

Ok, thanks for the fast reply, i already look at this but i struggle how i can change the negative reading to charge and the positive to discharge. I try it again…

You don’t have to. The Riemann Sum helper will do that for you.

Oh wait. You said negative = charge.

You’re going to need a template sensor to reverse that, if you can’t do it on the device.

template:
  - sensor:
      - name: Corrected Battery Power
        state_class: measurement
        device_class: power
        unit_of_measurement: W
        state: "{{ -1 * states('sensor.your_battery_power_sensor_here') }}"
        availability: "{{ has_value('sensor.your_battery_power_sensor_here') }}"

Ok thanks to point me in the right direction.