i’m a bit confused, maybe some of you can help me or point to the right direction.
I have a smart meter which shows me the current consumption in W. (above +0 if I consuming energy and below -0 if I feed the energy back into the grid)
I want to calculate how much energy went back into the grid, means only consider the negativ numbers over time.
I’m a bit lost and have no Idea, I went already through some options below. But still not sure how to start.
I created a template sensor to consider only negative values:
sensor:
- platform: template
sensors:
power_out_cur:
friendly_name: "Aktuelle Stromeinspeisung"
device_class: "power"
value_template: "{{ states('sensor.stromzaehler_mt681_power_cur') | int if states('sensor.stromzaehler_mt681_power_cur') | int < 0 else 0 }}"
unit_of_measurement: "W"
If I understood correctly now I can add the Rieman Intgation? What should be the right integration method for a power kWh calculation?
Thanks this helps! I was able to solve my issue. This is what I did:
I have a sensor which tels me the current consumption in positive values and negative values (if I feed power back into the grid)
Based on this sensor I created a new template sensor, to consider only the negative values and transfer the negative values into positive:
sensor:
- platform: template
sensors:
power_out_cur:
friendly_name: "Aktuelle Stromeinspeisung"
device_class: "power"
value_template: "{{ states('sensor.stromzaehler_mt681_power_cur') | int *-1 if states('sensor.stromzaehler_mt681_power_cur') | int < 0 else 0 }}"
unit_of_measurement: "W"
then I used the “Riemann sum integral” Integration to create a sensor to calculate the kWh, method: left.
Not sure if it was needed but on top I added the following to my customize.yaml:
sensor.energieeinspeisung_gesamt:
state_class: total_increasing
device_class: energy
icon: mdi:home-export-outline
unit_of_measurement: kWh
Now everything is working fine as far as I can see.