wlcrs / huawei_solar

Home Assistant integration for Huawei Solar inverters via Modbus
GNU Affero General Public License v3.0
557 stars 89 forks source link

[Bug]: Huawei sensors are going unavailable sometimes #29

Closed gieljnssns closed 2 years ago

gieljnssns commented 2 years ago

System Health details

System Health

version core-2022.2.7
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.9.7
os_name Linux
os_version 5.10.98
arch x86_64
timezone Europe/Brussels
Home Assistant Community Store GitHub API | ok -- | -- Github API Calls Remaining | 5000 Installed Version | 1.22.0 Stage | running Available Repositories | 1060 Downloaded Repositories | 36
Home Assistant Supervisor host_os | Home Assistant OS 7.4 -- | -- update_channel | beta supervisor_version | supervisor-2022.01.1 docker_version | 20.10.9 disk_total | 457.7 GB disk_used | 112.5 GB healthy | true supported | true board | generic-x86-64 supervisor_api | ok version_api | ok installed_addons | Samba share (9.5.1), AdGuard Home (4.4.4), AppDaemon 4 (0.8.1), Caddy (1.6), Check Home Assistant configuration (3.9.0), Duck DNS (1.14.0), ESPHome (2022.1.4), Mosquitto broker (6.0.1), Studio Code Server (4.1.0), WireGuard (0.6.0), MariaDB (2.4.0), Samba Backup (5.0.0), InfluxDB (4.3.0), Grafana (7.4.1), Frigate NVR (2.3), SSH & Web Terminal (10.0.2), Glances (0.14.2), phpMyAdmin (0.7.0), Mealie (0.5.6), Arpspoof (1.0.0), Caddy 2 (1.1.0), Firefly iii (5.6.14-2)
Lovelace dashboards | 3 -- | -- resources | 17 views | 18 mode | storage
Spotify api_endpoint_reachable | ok -- | --

Describe the issue

My HA instance is connected to the internal wifi of the inverter And I'm using your latest version 1.0.0.a3, in the manifest.json it is still 1.0.0.a1

All Huawei sensors are going unavailable for some time.

Schermafbeelding 2022-02-16 om 14 07 47 Schermafbeelding 2022-02-16 om 14 10 03

Reproduction steps

  1. Connect to internal wifi
  2. Install integration
  3. Just wait ...

Relevant debug logs

This is the moment everything becomes unavailable

Deze fout is ontstaan door een aangepaste integratie.

Logger: custom_components.huawei_solar
Source: helpers/update_coordinator.py:193
Integration: Huawei Solar
First occurred: 11:40:50 (1 occurrences)
Last logged: 11:40:50

Timeout fetching HV20C0092844_data_update_coordinator data
Logger: huawei_solar.huawei_solar
Source: /usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py:270
First occurred: 11:46:01 (1 occurrences)
Last logged: 11:46:01

Could not read register value, has another device interrupted the connection?
Logger: pymodbus.client.asynchronous.async_io
Source: /usr/local/lib/python3.9/site-packages/pymodbus/client/asynchronous/async_io/__init__.py:307
First occurred: 12:02:41 (20 occurrences)
Last logged: 13:00:56

Failed to connect: [Errno 113] Connect call failed ('192.168.200.1', 6607)
Failed to connect: [Errno 110] Connect call failed ('192.168.200.1', 6607)
Logger: huawei_solar.huawei_solar
Source: /usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py:246
First occurred: 12:02:31 (105 occurrences)
Last logged: 13:05:51

Modbus client is not connected to the inverter.
NoneType: None

And this are all debug logs from going unavailable to available again, sorry for the very long logs...

https://paste.ubuntu.com/p/mFwtgHDwPK/

wlcrs commented 2 years ago

Thank you for providing the logs. I see frequent connection drops, do you have good connectivity to your inverter? Is the device connecting to the inverter WiFi close enough? Maybe you can run a ping to the inverter to check if you see the connection drops there too?

I'll increase the timeout values in an upcoming release, but I'm not sure that this will do much for you as the connections seem to drop entirely, and the Modbus-TCP implementation of Huawei does not handle this well. The integration periodically tries to reconnect (with a maximum of 5 seconds between attempts).

What inverter do you have?

gieljnssns commented 2 years ago

I have an sun2000-4ktl-m1 inverter with firmware version V100R001C00SPC141 It is located about 1,5m of the intel nuc I'm using for HA. There is no wall in between them.

gieljnssns commented 2 years ago

Indeed with ping I also have bad results C8884DD6-85E4-44DC-A384-DDD3F130066B

wlcrs commented 2 years ago

Yikes. Not much I can do in such a situation. I suggest you look into improving stability of your connection. I'll also be documenting the usage of the physical RS485_1 Modbus-interface on the future. You might consider using that instead.

gieljnssns commented 2 years ago

@wlcrs I have downgraded my inverter to V100R001C00SPC135 again. Then the ping times where normal again. But the modbus port changed to 502 again. There is no way to change te modbus port in your integration. So I updated to V100R001C00SPC140. modbus port is 6607 again. And ping responses are normal. 2EE602DE-BE64-4557-86E1-F2D1931C72CC

wlcrs commented 2 years ago

You can change the port by removing and reinstalling the integration

gugaspinto commented 2 years ago

Hello It happens to me... Unavailable sensors But only during 3 seconds... Can say, Around every 1h30m

Inverter firmware 141, last one

I'm connected over internal WiFi, with good coverage, with good ping, good connection. I'm using the stable version of the huawei_solar, I think it's 0.05 (after installing, I don't see the version... Sorry)

I only have 5 sensors activated on huawei_solar integration, but I update values every second.

I have changed from dongle LAN to internal WiFi, because I sow anywhere its faster...

My Log says SLAVEBUSY, as you can see above.

For my automations is important to have 1sec values. In Portugal we pay the electricity with a 15min balance, and my HA calculate that balance to make the automation triggers

There are some way to solve this?

Talking about performance... There are any difference between this integration and the HA Modbus?

Thanks for your GREAT WORK... Congratulations

IMG_20220222_200523

wlcrs commented 2 years ago

You are trying to read faster from the inverter than it can handle, hence the SlaveBusy errors. Nothing I can change about this.

Changing to the native HA Modbus integration will not solve this: you will just get the same SlaveBusy errors, without the advantage of the multi-register-reads that this integration performs.

In the beta versions I automatically retry on SlaveBusy errors.

gugaspinto commented 2 years ago

Reducing the number of activated entities in the integration will reduce the errors? For example, only the power yield 1 and 2

Do you know if the rs485 is faster? I don't have the necessary hardware... Rs2lan If it is a solution I could think about that...

Thanks for your patience 🙂

wlcrs commented 2 years ago

Sensors are bundled: one inverter bundle, one power meter bundle, one battery bundle, one pc string bundle. Enabling a sensor of one bundle will query all datafields of that bundle, regardless of how many are actually enabled.

I have not tried using the RS485_1 interface directly myself (yet). Any feedback would be appreciated on the performance of that interface vs using the WLAN or dongle.

On Tue, Feb 22, 2022, 23:00 gugaspinto @.***> wrote:

Reducing the number of activated entities in the integration will reduce the errors? For example, only the power yield 1 and 2

Do you know if the rs485 is faster? I don't have the necessary hardware... Rs2lan If it is a solution I could think about that...

Thanks for your patience 🙂

— Reply to this email directly, view it on GitHub https://github.com/wlcrs/huawei_solar/issues/29#issuecomment-1048253227, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQM5LFDGO74B3FGYFS77KTU4QBQTANCNFSM5ORSNESA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

tfriberg commented 2 years ago

I built a template to manage when the inverter is unresponsive, or turned off at night.

template:
  sensors:
    template_inverter_active_power_availability: 
      friendly_name: Inverter active power
      device_class: energy
      unit_of_measurement: 'W'
      value_template: '{{ 0 if states ("sensor.inverter_active_power") == "unavailable" else states ("sensor.inverter_active_power") }}'
image

This gives me live updates (and live daily yield numbers when the inverter is unreachable) on the front page (the gauges using sensor_inverter_active_power reports 0 when unavailable and does not replace the gauges with an error message). The calculations I do to present what the house consumes at the moment (solar power PLUS from grid MINUS to grid) is another template sensor;

    template_active_power_consumption:
      friendly_name: Power consumption
      device_class: energy
      unit_of_measurement: 'W'
      value_template: '{{ states ("sensor.inverter_active_power")|int(0) + states ("sensor.lgf_active_power_import") | int(0) - states ("sensor.lgf_active_power_export")|int(0) }}'

Hope this helps @gieljnssns.

It would, however, be very nice if the inverter reported 0 "out-of-the-box" when not reachable.

wlcrs commented 2 years ago

I understand that it would be nice to have those entities report as 0, but that is not easy to implement: returning 0 for some registers would cause all kinds of problems and unintended consequences (monotonically increasing registers like total yield for example).

I think that your approach with templates is the best way forward to be honest.

gugaspinto commented 2 years ago

The better solution is never have "unavailable" moments

What's your data update frequency? What kind of connection do you have with the inverter?

I collect data every second. I have some "unavailable" moments... I can say... 30 times a day...

I think it became worth when the integration updated to have rs485

I connect through dongle Lan directly to my router. I already tried inverter WiFi to my AP --> router. Same result

For me, it's impossible to have rs485 usb to my rpi. Can rs485 to Lan do a better result? Thanks

stefanhapper commented 1 year ago

@gugaspinto How do you manage to query the inverter every second? Even if update the inverter values every 10 seconds the inverter stops sending data to Huawei FusionSolar. Or you don't care that no data is sent to FusionSolar?

I have a SUN200 4.6 KTL-L1 with SPC124 and connect via AP wifi