I use a Riemann sum to calculate the solar energy produced by my Huawei solar
- platform: integration
source: sensor.input_power_with_efficiency_loss
name: solar_energy_riemann_k
unit_prefix: k
round: 3
- name: "input_power_with_efficiency_loss"
unique_id: "input_power_with_efficiency_loss"
unit_of_measurement: "W"
device_class: power
state_class: measurement
state: >-
{% set inverter_rating = 6000 %} {# adjust this value to the rated power of your inverter #}
{% set inpower = states('sensor.inverter_input_power')|float(0) %}
{% if inpower < (inverter_rating*0.1) %}
{{ inpower * 0.90 }}
{% elif inpower < (inverter_rating*0.2) %}
{{ inpower * 0.95 }}
{% else %}
{{ inpower * 0.98 }}
{% endif %}
Sometimes, not everyday, I get a negative value solar production.
In this case the riemann sum last value before the “drop” was 2653.76, then it changed to 2650.58. This caused the solar production to start with -3.xx kWh
May
Could it be related to the integrated sensor “input_power_with_efficiency_loss,” which, as shown in the screenshot, has some negative values at the beginning and end of the day?
Is it possible to ensure that this sensor only generates values greater than or equal to zero? I’m not sure if using the availability template would yield the same result.