wills106 / homeassistant-solax-modbus

SolaX Power Modbus custom_component for Home Assistant (Supports some Ginlong Solis, Growatt, Sofar Solar, TIGO TSI & Qcells Q.Volt Hyb)
285 stars 85 forks source link

[Bug]: 'Sofar' - 'HYD 10KTL-3PH' Corrupt Mobus Data Gets Accepted #774

Open fische11 opened 4 months ago

fische11 commented 4 months ago

Describe the bug

It seems that corrupt mobus data gets accepted from the LSE-3 Logger. Yesterday at 2am the all the data in the following category where completely random for one response: Electric Power (0x0680-0x06BF)

I might found a possible solution on how to check the modbus data for errors as it seems that the LSE-3 does not check the CRC itself: https://github.com/StephanJoubert/home_assistant_solarman/issues/120#issuecomment-1282318815

Integration Version

2024.02.6

Homeassistant core version

2024.2.3

Inverter brand

Sofar

Plugin used

plugin_sofar.py

Serial prefix

SP2ES1

Connection Method

LSE-3

Detailed Error Log

No response

Additional context

No response

hruskaexe commented 4 months ago

Hello, I have same Sofar device and after update to this version 2024.02.6, communication always drops out after about an hour. Please fix it, I'm losing my data.

Log of some errors (but all entities are not updated anymore):


Logger: custom_components.solax_modbus Source: custom_components/solax_modbus/init.py:504 Integration: SolaX Inverter Modbus (documentation, issues) First occurred: 21:46:01 (32 occurrences) Last logged: 21:51:17

sofar: read failed at 0x61b: Battery_power_4 sofar: read failed at 0x61c: battery_temperature_4 sofar: read failed at 0x61d: battery_capacity_charge_4 sofar: read failed at 0x61e: battery_state_of_health_4 sofar: read failed at 0x61f: battery_charge_cycle_4


Logger: custom_components.solax_modbus Source: custom_components/solax_modbus/init.py:504 Integration: SolaX Inverter Modbus (documentation, issues) First occurred: 23:08:28 (15 occurrences) Last logged: 23:13:28

sofar: read failed at 0x41a: heatsink_temperature_1 sofar: read failed at 0x41b: heatsink_temperature_2 sofar: read failed at 0x420: module_temperature_1 sofar: read failed at 0x421: module_temperature_2 sofar: read failed at 0x42c: rtc

hruskaexe commented 4 months ago

UPDATE:

Log of errors in previous message are before connection drop out. After is in log this:


Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:240 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 05:00:21 (7 occurrences) Last logged: 08:01:18

[281473607444416] Modbus Error: [Input/Output] ERROR: No response received after 3 retries Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 962, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/select/init.py", line 195, in async_handle_select_option await self.async_select_option(option) File "/config/custom_components/solax_modbus/select.py", line 106, in async_select_option await self._hub.async_write_registers_single(unit=self._modbus_addr, address=self._register, payload=payload) File "/config/custom_components/solax_modbus/init.py", line 425, in async_write_registers_single return await self._client.write_registers(address, payload, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 175, in async_execute raise ModbusIOException( pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ERROR: No response received after 3 retries


Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:240 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 05:40:33 (13 occurrences) Last logged: 08:11:25

[281473607444416] Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.0.205:8899] Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 962, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/select/init.py", line 195, in async_handle_select_option await self.async_select_option(option) File "/config/custom_components/solax_modbus/select.py", line 106, in async_select_option await self._hub.async_write_registers_single(unit=self._modbus_addr, address=self._register, payload=payload) File "/config/custom_components/solax_modbus/init.py", line 425, in async_write_registers_single return await self._client.write_registers(address, payload, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pymodbus/client/mixin.py", line 426, in write_registers return self.execute( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 147, in execute raise ConnectionException(f"Not connected[{self!s}]") pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.0.205:8899]

wills106 commented 4 months ago

Is this still with 2024.02.6 or 2024.03.1?

hruskaexe commented 4 months ago

Now, I updated to 2024.03.1 and communication worked longer then hour, but the same result.

BEFORE:

Logger: custom_components.solax_modbus Source: custom_components/solax_modbus/init.py:507 Integration: SolaX Inverter Modbus (documentation, issues) First occurred: 09:35:07 (277 occurrences) Last logged: 11:47:39

sofar: read failed at 0x41a: heatsink_temperature_1 sofar: read failed at 0x41b: heatsink_temperature_2 sofar: read failed at 0x420: module_temperature_1 sofar: read failed at 0x421: module_temperature_2 sofar: read failed at 0x42c: rtc


AFTER:

Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:240 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 12:00:19 (3 occurrences) Last logged: 12:20:19

[281472915908544] Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.0.205:8899] Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 962, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/select/init.py", line 195, in async_handle_select_option await self.async_select_option(option) File "/config/custom_components/solax_modbus/select.py", line 106, in async_select_option await self._hub.async_write_registers_single(unit=self._modbus_addr, address=self._register, payload=payload) File "/config/custom_components/solax_modbus/init.py", line 428, in async_write_registers_single return await self._client.write_registers(address, payload, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pymodbus/client/mixin.py", line 426, in write_registers return self.execute( ^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 147, in execute raise ConnectionException(f"Not connected[{self!s}]") pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.0.205:8899]


Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:240 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 12:30:50 (4 occurrences) Last logged: 13:01:05

[281472915908544] Modbus Error: [Input/Output] ERROR: No response received after 3 retries Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 962, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/select/init.py", line 195, in async_handle_select_option await self.async_select_option(option) File "/config/custom_components/solax_modbus/select.py", line 106, in async_select_option await self._hub.async_write_registers_single(unit=self._modbus_addr, address=self._register, payload=payload) File "/config/custom_components/solax_modbus/init.py", line 428, in async_write_registers_single return await self._client.write_registers(address, payload, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 175, in async_execute raise ModbusIOException( pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ERROR: No response received after 3 retries

hruskaexe commented 4 months ago

More information about my configuration.

I have Modbus converter USR-W610, with terminator resistor on both sides, transparent mode - Modbus RTU over TCP, 5 seconds update, communicates with HASS via WiFi.

Before version 2024.02.6 it works.

wills106 commented 4 months ago

Do you get this error when you are trying to write to the Inverter then?

hruskaexe commented 4 months ago

When I restart HASS, before connection error, I can change parameters. I try it with "Energy Storage Mode", but I see, that duration between send start and send done confirmation is about 30 seconds. When a disconnect communication error occurs, I can't change parameters and in log is this:


Logger: homeassistant.components.websocket_api.http.connection Source: components/websocket_api/commands.py:240 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 13:22:38 (2 occurrences) Last logged: 13:24:23

[281472890835136] Modbus Error: [Input/Output] ERROR: No response received after 3 retries Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 240, in handle_call_service response = await hass.services.async_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2279, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2316, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in entity_service_call single_response = await _handle_entity_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 962, in _handle_entity_call result = await task ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/select/init.py", line 195, in async_handle_select_option await self.async_select_option(option) File "/config/custom_components/solax_modbus/select.py", line 106, in async_select_option await self._hub.async_write_registers_single(unit=self._modbus_addr, address=self._register, payload=payload) File "/config/custom_components/solax_modbus/init.py", line 428, in async_write_registers_single return await self._client.write_registers(address, payload, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 175, in async_execute raise ModbusIOException( pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ERROR: No response received after 3 retries

cschlipf commented 3 months ago

@hruskaexe Are you also using the LSE-3 logger or have you connected to the RS485 port? In the later, did you properly terminate the bus? See also #644, which seems to be a duplicate of your issue. However your issue does not seem to be related to what @fische11 reports here.

cschlipf commented 3 months ago

@fische11 Is it similar to what I see on my side with the LSE-3 as well?

image

So from time to time the LSE reports a power generation of more than 6 MW, which I doubt given that I just have 9.84 kWp installed.

If your data looks similar an easy fix might be to sanitize unrealistic values and simply ignore these.

fische11 commented 3 months ago

@cschlipf Yes, but for me it was just not that often. I already posted a potential fix in my first post. As this issue does not seem to be a priority I switched to this RS485 Adapter: https://www.waveshare.com/wiki/2-CH_RS485_TO_ETH_(B) So far the data is always correct with the modbus adapter but the connection gets lost sometimes and you have to restart the inverter. I think the baudrate was set to high. Now with a lower baudrate it seems to be stable.

cschlipf commented 3 months ago

@wills106

What do you think about a simple sanitizer?

This is not a 100% fix of course, but in my case this would filter out about 99% of false values.

fische11 commented 3 months ago

@cschlipf I got it working now without any problems for weeks with this adapter: https://www.waveshare.com/wiki/2-CH_RS485_TO_ETH_(B) You MUST update the firmware of the inverter to V110051 or later. This firmware fixes the connection issues with RS485, otherwise the inverter will disconnect the Modbus every 3 hours or so. Modbus Baudrate: 115200 Modbus Gateway Type: Auto query storage type -> See Image Modbus

I can now get updates ever second without any problems. This is in my opinion the best solution for Sofar inverters.

cschlipf commented 3 months ago

I know that I need to use V110051. I have it running since 3 months now.

However I would like to avoid having to buy new hardware - especially as the LSW-3 is a standard Sofar hardware and is used by many people today.

hruskaexe commented 2 months ago

@hruskaexe Are you also using the LSE-3 logger or have you connected to the RS485 port? In the later, did you properly terminate the bus? See also #644, which seems to be a duplicate of your issue. However your issue does not seem to be related to what @fische11 reports here.

Hello, thanks for your reply, I want to write you result of my problem. I have RS485 port.

I tried some wiring changes. With both resistors (terminators) connected it produced the same errors. So I changed the device to Waveshare (in link) and I connected the common ground (GND) (Sofar with Waveshare) and also I grounded the frame of the device (PE) together with the metal sheath of the cable. Now it seems to be working good and stable.

Waveshare: https://www.waveshare.com/product/iot-communication/wired-comm-converter/ethernet-to-uart-rs232-rs485/rs232-485-to-wifi-eth-b.htm