Energy Dashboard - Strange PV readings

I have a Huawei PV installation for some years. Everything worked fine but since some time I see sometimes (read mostly) very strange reading in the Energy Dashboard.
Sometimes I have a normal Solar Production bargraph:


But unfortunately on other days, with approx. same solar production I get these results:


For sure, the PV installation is working normally, I have a Dashboard card which gives me the actural solar production and this behaves normally.

I’ve setup my Energy dashboard as follow:
I have a sensor called sensor.inverter_input_power from the Huawei integration that gives me the actual solar production.
Into sensor.yaml I create a sensor “sensor.opbrengt_zonnepanelen”:

- platform: integration
    source: sensor.inverter_input_power
    name: opbrengst zonnepanelen
    unit_prefix: k
    unit_time: h
    round: 2

Finally into templates.yaml I create the sensor for the Energy dashboard:

 - sensor:
      - name: totale productie van de zonnepanelen
        unique_id: total_solar_production
        unit_of_measurement: "kWh"
        icon: mdi:solar-power
        state: "{{ states ('sensor.opbrengst_zonnepanelen') | float(0) }}"
        device_class: energy
        state_class: total_increasing

The actual solar production is correct in HA but for some reason mostly the Energy Dashboard information is totally wrong.

Thanks for any help!

This is bad. If your sensor opbrengst_zonnepanele becomes unavailable the template sensor will report 0 instead of unavailable. When that happens the entire total is added to the energy dashboard. All you need is an availability template to prevent this happening:

 - sensor:
      - name: totale productie van de zonnepanelen
        unique_id: total_solar_production
        unit_of_measurement: "kWh"
        icon: mdi:solar-power
        state: "{{ states ('sensor.opbrengst_zonnepanelen') | float(0) }}"
        device_class: energy
        state_class: total_increasing
        availability: "{{ states ('sensor.opbrengst_zonnepanelen') | is_number }}"

total → 0 → toal : add the entire total to the energy dashboard

total → unavailable → total : carry on counting from where it left off.

Also why are you duplicating the Riemann sum with a template sensor?

Thanks for your prompt reply.
I’ve copy/paste your solution and will see how it behaves.

I thought all steps were required:
1/ The Huawei integration gives the actual production in Watt
2/ The Riemann sum (into sensor.yaml) ‘converts’ it to kW
3/ The template finally count the Riemann sum and ‘converts’ the total solar production in kWh

If it can be easier please tell me!

Nope kWh. Which is all you need for the energy dashboard.

Hmmm, I will try that

It does require the power sensor you are feeding it to have the correct state_class (power) and device class (measurement). Then it will have the correct state class (total_lincreasing) and device class (energy).