Wrong values passed from sensor template to integration

I’m trying to integrate two Solar Inverters into the energy tab of Home Assistant.

I have the following code the values of panourisolare_productie_huawai and panourisolare_productie_fronius are correct:

SOLAR Productie Fronius 6kw: 4206.0
SOLAR Productie Huawai 3kw 2241.0

  - platform: template
        device_class: power
        friendly_name: "SOLAR Productie Huawai 3kw"
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.sun2000l_3ktl_2101073801hvk7000518') | float }}"
        device_class: power
        friendly_name: "SOLAR Productie Fronius 6kw"
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.power_photovoltaics_fronius_power_flow_0_192_168_1_184') | float }}"
  - platform: integration
    source: sensor.panourisolare_productie_huawai
    name: SOLAR Productie Huawai 3kw
    unit_of_measurement: Wh
    # unit_prefix: k
    round: 2
  - platform: integration
    source: sensor.panourisolare_productie_fronius
    name: SOLAR Productie Fronius 6kw
    unit_of_measurement: Wh
    # unit_prefix: k
    round: 2

However when I use the integrations to Energy, values are very different:

sensor.solar_productie_fronius_6kw: 881.351
sensor.solar_productie_huawai_3kw: 660.364

Any help is appreciated. Thanks!

How do you mean different? Different from what?

the integrations platform starts from 0 Wh.

My expectation is that the passed value from the template definition to the integration definition to be the same.

Based on the initial values, in the Energy tab I should have 4206.0 + 2241.0 = 6447 Wh produced by the solar panels, however since the values are modified I get 881.351 + 660.364 = 1541 Wh

You did not understand what you are doing here.

Your both template sensors are power device classes (in your example ‘Watt’)
The platform integration calculates the amount of energy from your power sensors via riemann sum.

When one of your inverters produces 1000 W for one hour, your integration sensor will display 1000 Wh respectively 1 kWh

Understanding Home Energy Management - Home Assistant (home-assistant.io)

by the way: Welcome to Home Assistant forum :wink:

Thanks @mxwi
Will look into it.

Apart from what mxwi said, for the Fronius device you can just use the sensor.energy_total_fronius_inverter_1_0_192_168_1_184 entity for the energy panel to get more reliable results without the need for further calculation (see Fronius - Home Assistant).