Integration Solar inverter huawei 2000L

Joaquín I’m interested in knowing how you configured so many sensors.
I have an integrated 5kw inverter, but I don’t know the name of the sensors to later create those cards.
Could you tell me the name or the code snippet to read those attributes?

Joaquín me interesa saber como configurastes tantos sensores.
Tengo un inversor de 5kw integrado, pero desconozco el nombre de los sensores para crear luego esas tarjetas.
Podrías indicarme el nombre o el fragmento de código para leer esos atributos?

how did you separate data for each string? and which card are these?

Create sensors from each attribute by using templates.

Heres my code for example:

- platform: huawei_solar   
    host: '192.168.1.40'
    optimizers: false
    battery: false
    
  - platform: template
    sensors:
      pv_input_power:
        friendly_name: "DC Production"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'W'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'input_power') }}"
        
  - platform: template
    sensors:
      pv_daily_yield:
        friendly_name: "Daily Yield"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'daily_yield') }}"
   
  - platform: template
    sensors:
      pv_total_yield:
        friendly_name: "Total Yield"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'total_yield') }}"
        
  - platform: template
    sensors:
      pv_string_01_voltage:
        friendly_name: "Pv String 01 Voltage"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'V'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'pv_string_01_voltage') }}"

  - platform: template
    sensors:
      pv_string_01_current:
        friendly_name: "PV String 01 Current"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'A'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'pv_string_01_current') }}"
        
  - platform: template
    sensors:
      pv_string_02_voltage:
        friendly_name: "PV String 02 Voltage"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'V'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'pv_string_02_voltage') }}"
        
  - platform: template
    sensors:
      pv_string_02_current:
        friendly_name: "PV String 02 Current"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'A'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'pv_string_02_current') }}"
        
  - platform: template
    sensors:
      pv_active_power:
        friendly_name: "Power Meter Active Power"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'power_meter_active_power') }}"
        
  - platform: template
    sensors:
      consumption:
        friendly_name: "Consumption"
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
        value_template: '{{ states("sensor.sun2000_5ktl_l1") |float - states("sensor.pv_active_power") | float }}'
        
  - platform: template
    sensors:
      pv_device_status:
        friendly_name: "Device Status"
        #entity_id: sensor.sun2000_5ktl_l1
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'device_status') }}"

  - platform: template
    sensors:
      pv_string_02_power:
        friendly_name: "PV String 02 Power"
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
        value_template: '{{ states("sensor.pv_string_02_voltage") |float * states("sensor.pv_string_02_current") | float / 1000|round(2) }}'
        
  - platform: template
    sensors:
      pv_string_01_power:
        friendly_name: "PV String 01 Power"
        unit_of_measurement: 'kW'
        icon_template: mdi:solar-power
        value_template: '{{ states("sensor.pv_string_01_voltage") |float * states("sensor.pv_string_01_current") | float / 1000|round(2) }}'

  - platform: template
    sensors:
      pv_efficiency:
        friendly_name: "Solar Efficiency"
        #entity_id: sensor.sun2000_5ktl_l1
        unit_of_measurement: '%'
        icon_template: mdi:solar-power
        value_template: "{{ state_attr('sensor.sun2000_5ktl_l1', 'efficiency') }}"
 

Cards are mini-graph-cards that have been horizontally and vertically stacked.

2 Likes

cheers mate it works great

All good, brother, glad to help.

First of all thanks EmilV2 for great Job

I have core 2021.7.2 and i have error:

2021-07-19 16:32:56 ERROR (MainThread) [homeassistant.components.sensor] huawei_solar: Error on device update!
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 432, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 601, in async_device_update
await task
File “/usr/local/lib/python3.9/concurrent/futures/thread.py”, line 52, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/huawei_solar/sensor.py”, line 297, in update
self._grid_exported_energy = self._inverter.get(“grid_exported_energy”).value
File “/usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py”, line 39, in get
reg = REGISTERS[name]
KeyError: ‘grid_exported_energy’

I already changed to huawei-solar>=0.1.0,<1.0.0, but without sucess

Any help will be apreciated

Thank You

Hi,

In the last few days I have been trying to put up and running Home Assistant with integration with my Huawei SUN2000-3KTL-M0.

It took time, but today I finally was able to get the first data from the inverter .

For that I must thank Emilv2, Rafal and all others that are supporting the community,

The problem I have is that I can’t reconcile all numbers I read from the inverter through huawei_solar and those I get from Huawei fusion portal.

I am trying to get daily total numbers for production, imported electricity from grid and exported energy to grid. In the post I replying to, I am looking for daily values for #5 (is counted), #6 (grid_exported_energy) and #8 (grid_accumulated_energy).

Looking at all numbers read on the sensor, both grid_exported_energy and grid_accumulated_energy are total counters, adding up all values since the inverter was first connected (like total_yeld). For daily production there is daily_yeld

Where to get daily totals for these two measures?

Thanks in advance…

There is only daily_yield,
For daily, monthly, yearli sensors you can use utility_meter.

- platform: template
  sensors:
    grid_exporterd_energy:
      friendly_name: "Prąd oddany do sieci"
      unit_of_measurement: 'kWh'
      icon_template: mdi:transmission-tower
      value_template: "{{ state_attr('sensor.sun2000_8ktl_m0', 'grid_exported_energy') }}"
 
    grid_accumulated_energy:
      friendly_name: "Prąd pobrany z sieci"
      unit_of_measurement: 'kWh'
      icon_template: mdi:transmission-tower
      value_template: "{{ state_attr('sensor.sun2000_8ktl_m0', 'grid_accumulated_energy') }}"

    daily_yield:
      friendly_name: "Produkcja dziś"
      unit_of_measurement: 'kWh'
      icon_template: mdi:transmission-tower
      value_template: "{{ state_attr('sensor.sun2000_8ktl_m0', 'daily_yield') }}"

    total_yield:
      friendly_name: "Produkcja total"
      unit_of_measurement: 'kWh'
      icon_template: mdi:transmission-tower
      value_template: "{{ state_attr('sensor.sun2000_8ktl_m0', 'total_yield') }}"

    energy_used:
      friendly_name: "Zużycie prądu dom"
      unit_of_measurement: 'kWh'
      value_template: >
        {{ '%0.2f' | format(states('sensor.total_yield') | float - 
                            states('sensor.grid_exporterd_energy') | float + 
                            states('sensor.grid_accumulated_energy') | float) }}
utility_meter:
  daily_grid_exporterd_energy:
    source: sensor.grid_exporterd_energy
    cycle: daily  
  daily_grid_accumulated_energy:
    source: sensor.grid_accumulated_energy
    cycle: daily

  dzienne_zuzycie:
    source: sensor.energy_used
    cycle: daily
  miesieczne_zuzycie:
    source: sensor.energy_used
    cycle: monthly
  miesieczna_produkcja:
    source: sensor.total_yield
    cycle: monthly
  roczne_zuzycie:
    source: sensor.energy_used
    cycle: yearly  
  roczna_produkcja:
    source: sensor.total_yield
    cycle: yearly
2 Likes

One question mate have you able to achieve that dc production and consumption be shown on the same graph? Not two separate ones ?

You use the mini-graph-card and place 2 entities on it, like so:

      - animate: true
        entities:
          - color: '#FDCA40'
            entity: sensor.pv_string_01_power
            name: North
            show_state: true
            smoothing: true
          - color: '#3772FF'
            entity: sensor.pv_string_02_power
            name: West
            show_state: true
            smoothing: true
        font_size: 100
        font_size_header: 15
        footer: null
        hour24: true
        hours_to_show: 12
        icon: mdi:flash
        line_width: 1.5
        name: Power Production (DC) - North vs West
        points_per_hour: 12
        show:
          fill: fade
          icon: false
          labels: false
          name: true
          points: false
          state: true
        type: custom:mini-graph-card

image

2 Likes

Hi,

I have problems to connect the inverter to Homeassitant.
The inverter is LAN and Wifi connected, and Homeassistant reads data from wifi IP.

Everything works fine, until I lost the internet connection or I reboot the homeassitant.

When that occurs, I have to connect to inverter, reconect the inverter to wifi and reboot the homeassitant, and it sometimes succes…

Now is working again, but is stressful.

Is it possible connect the inverter only by ethernet cable and get data from its to Homeassitant?

Logger: huawei_solar.huawei_solar
Source: /usr/local/lib/python3.8/site-packages/huawei_solar/huawei_solar.py:295
First occurred: 18:18:31 (1 occurrences)
Last logged: 18:18:31

failed to connect to device, is the host correct?
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/huawei_solar/huawei_solar.py", line 291, in read_register
      response = self.client.read_holding_registers(
        File "/usr/local/lib/python3.8/site-packages/pymodbus/client/common.py", line 114, in read_holding_registers
            return self.execute(request)
              File "/usr/local/lib/python3.8/site-packages/pymodbus/client/sync.py", line 109, in execute
                  return self.transaction.execute(request)
                    File "/usr/local/lib/python3.8/site-packages/pymodbus/transaction.py", line 173, in execute
                        response, last_exception = self._transact(
                          File "/usr/local/lib/python3.8/site-packages/pymodbus/transaction.py", line 290, in _transact
                              result = self._recv(response_length, full)
                                File "/usr/local/lib/python3.8/site-packages/pymodbus/transaction.py", line 321, in _recv
                                    read_min = self.client.framer.recvPacket(min_size)
                                      File "/usr/local/lib/python3.8/site-packages/pymodbus/framer/__init__.py", line 49, in recvPacket
                                          return self.client.recv(size)
                                            File "/usr/local/lib/python3.8/site-packages/pymodbus/client/sync.py", line 89, in recv
                                                return self._recv(size)
                                                  File "/usr/local/lib/python3.8/site-packages/pymodbus/client/sync.py", line 298, in _recv
                                                      return self._handle_abrupt_socket_close(
                                                        File "/usr/local/lib/python3.8/site-packages/pymodbus/client/sync.py", line 343, in _handle_abrupt_socket_close
                                                            raise ConnectionException(msg)
                                                            pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] ModbusTcpClient(192.168.50.239:502): Connection unexpectedly closed 0.000247 seconds into read of 8 bytes without response from unit before it closed connection

Hello all,
Thanks everyone for the contribution and insights about this topic. I have the latest firmware on wifi my dongle and I have an 8KTL - M1 3 phase. 502 port is open and via manual modubus connection I get a True response and the library is installed via pip3 and also via hacs.
My question is if somebody encountered the error of always saying that there is “another client connected.” - from hass and terminal as well. (I closed the fusionsolar mobile app and website and waited for some time).
Thanks!

Hi all,
Just got one of these invertors now trying to use this integration, but it just won’t work, whenever I add it and try and restart HA it just kills it. Removing the folder from Custom Integrations resolves it.
Since HA refuses to restart there is nothing in the logs.

I’ve seen some posts on updating the manifest file, but this hasn’t done anything, this is my manifest file for the component:

{
  "domain": "huawei_solar",
  "name": "huawei_solar",
  "documentation": "https://github.com/Emilv2/huawei_solar",
  "dependencies": [],
  "codeowners": ["Emilv2"],
  "requirements": ["huawei-solar>=0.1.0,<1.0.0"],
  "version": "0.2.0"
}

Perhpas I’m missing something, or there is another dependency that this needs?

Running core-2021.7.2 in Docker if the version is perhaps an issue?

Any help wouldbe appreciated.

try in the terminal on your pc to use the python package and see if that works before using it on HA, maybe you have the same problem as me, see above.

No idea how to do that, I don’t use python so not terribly familiar with it.

see if you receive anything after running python3 and these commands from a previous answer:

I can connect successfully (got a True) but after that, I doesn’t seem to read the register

Hooray, Just found the answer, thanks to somebody from the Huawei forums
https://forum.huawei.com/enterprise/en/sun2000-smart-dongle-modbus-tcp-issues/thread/675885-100027?page=3

from pymodbus.client.sync import ModbusTcpClient as ModbusClient

import time


client = ModbusClient("192.168.1.14", port=502)

client.connect()


if client.connect():


    time.sleep(1)

    

    rr = client.read_holding_registers(0x7D50, 0x02, unit=1) #32080 => active_power

    activePowerInv=rr.registers[1]

    print(activePowerInv)

“The trick is to specify the unit id (equal to 1) on each read_holding call. The dongle doesn’t answer to any request if the unit is not specified.”

This works along the FusionSolar app/website.

@Emilv2 thanks for your HASS plugin. I think that the code above may need to be integrated in the plugin, because as it is now, it didn’t work, at least for my configuration (KTL8-M1, 3P + smart dongle at version 122)

Only since version 120, the WLAN dongle allows the communication via 502 port directly.
For those that need an update for their wlan dongle just login in the fusionsolar web app, https://eu5.fusionsolar.huawei.com/ go to Plants > Device Management > Upgrade Management > Add (top right) select dongle > target xxxSPC122 then your dongle should appear in the next input or search for it
It will take a while (20mins), then check the status of the update, mine stated initially as “Delayed”, then I restarted the inverter (it applies the update when the dongle restarts).

1 Like

It was posted here also few times.

1 Like

@ligeza thanks for letting me know, sorry wasn’t able to read every single post. I really thought I was on to something :innocent:

Hopefully it can be integrated in the plugin.

Hi guys and welcome in this forum!
This thread is a valuable repository of knowledge about connecting to the SUN2000 inverter, so now I am able to monitor my SUN2000 inverter with hard.
I just want to share that If someone is struggling in configuring a router for accessing SUN2000 internal WiFi (especially using DD-WRT) I think that my blogpost can help with this:
https://skyboo.net/2021/07/how-to-connect-to-sun2000-from-dd-wrt/

regards!

1 Like