Struggling to setup Energy integration for Huawei Solar system with battery

Struggling to setup Energy integration (read Solar production) in a correct way.
I have a Huawei SUN2000 solar system with a battery. The default entities/sensors from the custom integration GitHub - Emilv2/huawei_solar: Home Assistant custom component for Huawei inverters are:
daily_yield : sensor that represents the daily energy in kWh (produced by the solar panels or stored in the battery) given to my home.
total_yield: sensor that represents the total energy in kWh (produced by the solar panels or stored in the battery) given to my home.
storage_charge_discharge_power: sensor that represents power in Watt van actual charge (+) or discharge (-) of battery
storage_total_charge: sensor in kWh with total charged energy in battery
storage_total_discharge: sensor in kWh with total discharged energy in battery

I understood that the energy integration wants sensor with total amount of energy in kWh.
For the grid (public electrical network) I use the DSMR integration and get:
energy_delivered_tariff1: total amount of energy delivered at daytime
energy_delivered_tariff2: total amount of energy delivered at nighttime
energy_returned_tariff1: total amount of energy returned / injected at daytime
energy_returned_tariff2: total amount of energy returned / injected at nighttime

For the grid and the battery the above mentioned sensors seems to work correct.
Problem is the Solar Production. The custom entity also has an entity called ‘sensor.sun2000_4_6ktl_l1_hvserialnumber’ with a state and a lot of attributes.
I found out that the attribute ‘input power’ gives the actual solar panel production.
I made a template:

template:
  - sensor:
        - name: pv_actual_yield
          state: "{{ state_attr('sensor.sun2000_4_6ktl_l1_serialnumber', 'input_power') | float }}"
          unit_of_measurement: "W"

The energy integration needs sensors in kWh with the total, increasing value. I made a sensor based on the Riemann sum integral integration. This integrations makes a sum of the produced power in Watts to energy in (k)Wh.

sensor:
  - platform: integration
      source: sensor.pv_actual_yield
      name: total_yield_pv
      unit_prefix: k
      round: 2

This creates a sensor sensor.total_yield_pv in kWh, what I need for the Energy integration.
The ‘Developer Tools’ are showing the sensor correctly with an increasing value.
For some reason, even after a restart I’m not able to select this sensor in the Energy integration.
I tried to add ‘device_class: energy’ and ‘device_state: measurement’ but this is not allowed in an integration.

Could you help me to sort out this problem?

Thanks to read my complete story/post. I wanted to explain as much as detailed in order to hopefully get an answer to this complicated situation.

What you are looking for is state_class: total_increasing or state_class: total - but I’m not 100% sure about their differences.

Thanks for your answer. I’m not sure you are right.
Below you see I can select the total_yield sensor:


This entity has below attributes:

As you can see, I don’t see any total_increasing or total as state_class
Anyway as I already mentioned: it’s not possible to add a state_class or device_state to a sensor integration.

Afaik you can do it with customize.
This entity is configured wrongly - either by customize or by the integration itself - if latter, please open an issue at Issues ¡ home-assistant/core ¡ GitHub - it should also raise some warning in the logs.
see New sensor state class: total | Home Assistant Developer Docs

Please clarify your comments.
Could you chase me in the right direction what I have to customize
Which entity is wrongly configured? I suspect it is generated by the custom integrations so why should I open an issue at home-assistant/core?

Oh, I missed this was a custom component - in this case file the issue there.
Your total_yield_... sensor

Note that setting last_reset for sensors with state class measurement is still deprecated.

Anyway this total_yield sensor from the custom integration is not usefull for me.

I’v added to my customize.yaml:

sensor.total_yield_pv:
  state_class: total_increasing

Configuration check passed, restarted HA and check by ‘Developer Tools’.
sensor.total_yield_pv has an attribute state_class: total (not total_increasing).
Unluckely could not select this entity as Solar panel in the Energy integration.
Added also device_class: energy in customization but no luck…

Any idea?

My last idea would be to wait an hour or two until long-term statistics are generated for that entity - if it doesn’t appear then too I don’t know.

Hello @Johanvh did you end up getting working okay in the end?
I’ve the same environment and am only embarking on getting this going now… :slight_smile:
Any help would be gratefully appreciated.

Hi, sorry for my late reply. You still need help? So far everything works in my case.

Hi @Johanvh , yep all up and running now.
I had to enable energy in my config.yaml

Curious though, what attributes are you using in your dashboard?

I added the two items @Johanvh mentioned in the 1st post but get Screenshot 2022-10-11 at 21.25.21
Anything I miss so far? I don’t have a customize.yml file to add the total_increasing stuff to.

Checked my configurations, as it is already a year ago I’ve setup.
For the Energy dashboard solar panel I use below entry (naming is in Dutch):

This sensor is created in template.yaml:
P.S. I have a seperate template.yaml. My configuration.yaml contains
template: !include template.yaml

In the energy dashboard I use “sensor.total_solar_production”

  • 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 sensor “sensor.opbrengst_zonnepanelen” means solar productions used in the above template is created in “sensor.yaml”:
P.S. I have again a seperate sensor.yaml. configuration.yaml has
sensor: !include sensor.yaml

  • platform: integration
    source: sensor.input_power
    name: opbrengst zonnepanelen
    unit_prefix: k
    unit_time: h
    round: 2

The source for this sensor comes from “sensor.input_power”; the Huawei integration

Hope this clariefies a lot

Hey Joran,

Is the opbrengst van de zonnepanelen entity more acurrate?
I’ve just installed this integration, but the solar produced is a lot lower then the provided apps say. (Might be caused because I have a battery too).

Do you still need this with the latest version of the integration?

Hi Marc,

It seems that the Huawei application (or website) is delayed. Home Assistant gets the information straight from the inverter so it’s direct real-time information. It is also updated much faster in Home Assistant compared to the Huawei portal… I have a battery as well but this is not related to the solar panel production.

I installed the integration by HACS so I’m informed once the integration has an update and I always use the latest version

1 Like

Hi, This might be a border question to the topic but I’m about to select the brand for my new solar installation. So I use the classic… “Besides it doesn’t work, how is it?” phrase.

I’m I able to control an Huawei battery to charge and discharge or is it only to watch what happens?

Apologies for delay, yes you have fully control on battery if you connect by serial communication or use the Huawei dongle