sunsynk icon indicating copy to clipboard operation
sunsynk copied to clipboard

umodbus doesn't work, but pymodbus does

Open dvoytik opened this issue 2 months ago • 5 comments

Issue related to

Sunsynk / mbusd Home Assistant Add-On

Describe the issue/bug

When I pick umodbus inverter driver I get the CRC errors (see below log). When I select the pymodbus driver, it works mainly, but it spills some errors once per ten minutes, which I guess I can ignore. I will try to play with settings like READ_SENSORS_BATCH_SIZE to try to make it completely stable.

Expected behavior No errors should occur

Your environment

  • Home Assistant version: Home Assistant OS 2025.10.4
  • Add-on:
    • Name: sunsynk-multi
    • Version: 0.9.2
  • Inverter:
    • Maker: Deye
    • Model: SUN-20K-SG01HP3-EU-AM2
    • Firmware: HMI: Ver 2001-C036, MAIN: Ver 3002-1077-1E08
  • Adapter details:
    • RS485
    • Cheap (3$) USB-RS485 without ground. Bought here: https://amzn.eu/d/9BR6HBm

You configuration


DRIVER: umodbus
INVERTERS:
  - SERIAL_NR: "1234567890"
    HA_PREFIX: SS
    MODBUS_ID: 1
    DONGLE_SERIAL_NUMBER: "0"
    PORT: ""
SENSOR_DEFINITIONS: three-phase-hv
SENSORS:
  - total_pv_energy
  - day_pv_energy
  - pv_power
  - pv1_power
  - pv1_voltage
  - pv1_current
  - pv2_power
  - pv2_voltage
  - pv2_current
  - grid_connected
  - overall_state
  - load_power
  - day_load_energy
  - grid_power
  - day_grid_import
  - total_grid_import
  - battery_1_power
  - battery_1_soc
  - battery_1_voltage
  - day_battery_charge
  - day_battery_discharge
  - total_battery_charge
  - total_battery_discharge
SENSORS_FIRST_INVERTER: []
MANUFACTURER: Sunsynk
READ_ALLOW_GAP: 2
READ_SENSORS_BATCH_SIZE: 20
SCHEDULES:
  - KEY: W
    READ_EVERY: 5
    REPORT_EVERY: 60
    CHANGE_ANY: false
    CHANGE_BY: 80
    CHANGE_PERCENT: 0
NUMBER_ENTITY_MODE: auto
PROG_TIME_INTERVAL: "15"
MQTT_PORT: 1883
MQTT_HOST: localhost
DEBUG_DEVICE: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A5069RR4-if00-port0
DEBUG: 0

Logs


s6-rc: info: service sunsynk: starting
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service sunsynk successfully started
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
[10:59:50] INFO: Starting the Sunsynk add-on
s6-rc: info: service legacy-services successfully started
[10:59:50] INFO    Loading config: /data/options.json
[10:59:50] WARNING 1234567890: Using port from debug_device: 
[10:59:50] WARNING Empty port, will use the debug device
[10:59:50] WARNING Use mbusd instead of connecting directly to a serial port
[10:59:50] WARNING Try *pymodbus* if your encounter any issues with *umodbus*
[10:59:50] INFO    sunsynk library version: 0.8.2
[10:59:50] INFO    Schedules:
+-----------+-----+------+--------+-----------+----------+------------+
|    Key    | src | Read | Report | Change by | Change % | Change any |
+-----------+-----+------+--------+-----------+----------+------------+
| date_time |     |  60  |   60   |           |          |    True    |
|     rw    |     |  5   |  300   |           |          |    True    |
|    enum   |     |  5   |  300   |           |          |    True    |
|     w     |  *  |  5   |   60   |    80.0   |          |            |
|    kwh    |     | 300  |  300   |           |          |            |
|  any_unit |     |  15  |  300   |           |          |            |
|  no_unit  |     |  15  |  300   |           |          |    True    |
+-----------+-----+------+--------+-----------+----------+------------+
[10:59:50] INFO    Importing sensor definitions three-phase-hv (view the source online: https://github.com/kellerza/sunsynk/tree/main/src/sunsynk/definitions/three_phase_hv.py )
[10:59:50] INFO    Added hidden sensors as other sensors depend on it: Device type, Protocol, Serial
[10:59:50] INFO    Connecting to serial:///dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A5069RR4-if00-port0
[10:59:50] INFO    Reading startup sensors Device type, Protocol, Serial
[10:59:51] INFO    ############################################################
[10:59:51] INFO                 Inverter serial number '****4274'
[10:59:51] INFO    ############################################################
[10:59:51] INFO    Device type: High voltage three phase hybrid, using the three-phase-hv sensor definitions
[10:59:51] INFO    Protocol version: 1.4
[10:59:51] INFO    Reading all sensors Device type, Protocol, Serial, Total PV Energy, Day PV Energy, PV power, PV1 power, PV1 voltage, PV1 current, PV2 power, PV2 voltage, PV2 current, Grid Connected, Overall state, Load power, Day Load Energy, Grid power, Day Grid Import, Total Grid Import, Battery 1 power, Battery 1 SOC, Battery 1 voltage, Day Battery Charge, Day Battery discharge, Total Battery Charge, Total Battery Discharge
  + Exception Group Traceback (most recent call last):
  |   File "<frozen runpy>", line 198, in _run_module_as_main
  |   File "<frozen runpy>", line 88, in _run_code
  |   File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/__main__.py", line 72, in <module>
  |     sys.exit(asyncio.run(main_loop()))
  |              ~~~~~~~~~~~^^^^^^^^^^^^^
  |   File "/usr/local/lib/python3.13/asyncio/runners.py", line 195, in run
  |     return runner.run(main)
  |            ~~~~~~~~~~^^^^^^
  |   File "/usr/local/lib/python3.13/asyncio/runners.py", line 118, in run
  |     return self._loop.run_until_complete(task)
  |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  |   File "/usr/local/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
  |     return future.result()
  |            ~~~~~~~~~~~~~^^
  |   File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/__main__.py", line 52, in main_loop
  |     await ist.connect()
  |   File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/a_inverter.py", line 149, in connect
  |     await self.read_sensors(sensors=sensors)
  |   File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/a_inverter.py", line 57, in read_sensors
  |     await self.inv.read_sensors(sensors)
  |   File "/.venv/lib/python3.13/site-packages/sunsynk/sunsynk.py", line 133, in read_sensors
  |     raise ExceptionGroup("Errors reading sensors", errs) from None
  | ExceptionGroup: Errors reading sensors (6 sub-exceptions)
  +-+---------------- 1 ----------------
    | umodbus.client.serial.redundancy_check.CRCError: CRCError reading 10 registers from 514: CRC validation failed.
    +---------------- 2 ----------------
    | umodbus.client.serial.redundancy_check.CRCError: CRCError reading 1 registers from 526: CRC validation failed.
    +---------------- 3 ----------------
    | AttributeError: AttributeError reading 1 registers from 529: 'Serial' object has no attribute 'host'
    +---------------- 4 ----------------
    | umodbus.client.serial.redundancy_check.CRCError: CRCError reading 1 registers from 625: CRC validation failed.
    +---------------- 5 ----------------
    | AttributeError: AttributeError reading 1 registers from 653: 'Serial' object has no attribute 'host'
    +---------------- 6 ----------------
    | umodbus.client.serial.redundancy_check.CRCError: CRCError reading 1 registers from 690: CRC validation failed.
    +------------------------------------
[10:00:11] WARNING: Halt add-on with exit code 1
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service sunsynk: stopping
s6-rc: info: service sunsynk successfully stopped
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped



dvoytik avatar Oct 26 '25 10:10 dvoytik

[10:59:50] WARNING Use mbusd instead of connecting directly to a serial port
[10:59:50] WARNING Try *pymodbus* if your encounter any issues with *umodbus*

kellerza avatar Oct 26 '25 14:10 kellerza

OK, looks like I didn't read thoroughly the Documentation... I didn't realize I should have installed " Modbus TCP to Modbus RTU Gateway Add-on". Thanks!

dvoytik avatar Oct 26 '25 16:10 dvoytik

I still see the following errors:

[17:46:46] ERROR   OSError in callback read_ss: OSError reading 8 registers from 0: failed to read register 0 - function code: 131 poll_need_to_read
Traceback (most recent call last):
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/timer_callback.py", line 81, in wrap_callback
    await cb_call
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/sensor_callback.py", line 113, in callback_sensor
    await ist.read_sensors(
    ...<2 lines>...
    )
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/a_inverter.py", line 57, in read_sensors
    await self.inv.read_sensors(sensors)
  File "/.venv/lib/python3.13/site-packages/sunsynk/sunsynk.py", line 135, in read_sensors
    raise errs[0] from None
OSError: OSError reading 8 registers from 0: failed to read register 0 - function code: 131 poll_need_to_read

Will try to switch back without mbusd

dvoytik avatar Oct 26 '25 16:10 dvoytik

Without mbusd enabled, I still get errors:

[17:51:46] ERROR   ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 690: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
Traceback (most recent call last):
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/timer_callback.py", line 81, in wrap_callback
    await cb_call
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/sensor_callback.py", line 113, in callback_sensor
    await ist.read_sensors(
    ...<2 lines>...
    )
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/a_inverter.py", line 57, in read_sensors
    await self.inv.read_sensors(sensors)
  File "/.venv/lib/python3.13/site-packages/sunsynk/sunsynk.py", line 135, in read_sensors
    raise errs[0] from None
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 690: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
[18:16:28] ERROR   ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 8 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
Traceback (most recent call last):
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/timer_callback.py", line 81, in wrap_callback
    await cb_call
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/sensor_callback.py", line 113, in callback_sensor
    await ist.read_sensors(
    ...<2 lines>...
    )
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/a_inverter.py", line 57, in read_sensors
    await self.inv.read_sensors(sensors)
  File "/.venv/lib/python3.13/site-packages/sunsynk/sunsynk.py", line 135, in read_sensors
    raise errs[0] from None
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ModbusIOException reading 8 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
[18:23:05] ERROR   ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
Traceback (most recent call last):
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/timer_callback.py", line 81, in wrap_callback
    await cb_call
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/sensor_callback.py", line 113, in callback_sensor
    await ist.read_sensors(
    ...<2 lines>...
    )
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/a_inverter.py", line 57, in read_sensors
    await self.inv.read_sensors(sensors)
  File "/.venv/lib/python3.13/site-packages/sunsynk/sunsynk.py", line 135, in read_sensors
    raise errs[0] from None
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
[18:25:00] ERROR   (1 in 5 min) ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
[18:25:55] ERROR   ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 141: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
Traceback (most recent call last):
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/timer_callback.py", line 81, in wrap_callback
    await cb_call
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/sensor_callback.py", line 113, in callback_sensor
    await ist.read_sensors(
    ...<2 lines>...
    )
  File "/.venv/lib/python3.13/site-packages/ha_addon_sunsynk_multi/a_inverter.py", line 57, in read_sensors
    await self.inv.read_sensors(sensors)
  File "/.venv/lib/python3.13/site-packages/sunsynk/sunsynk.py", line 135, in read_sensors
    raise errs[0] from None
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 141: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
[19:00:00] ERROR   (1 in 5 min) ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
[19:25:00] ERROR   (1 in 5 min) ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 1 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.
[20:20:00] ERROR   (1 in 5 min) ModbusIOException in callback read_ss: Modbus Error: [Input/Output] ModbusIOException reading 8 registers from 0: Modbus Error: [Input/Output] Request cancelled outside pymodbus.

I wonder if this is bad USB-RS485 dongle. The one I'm using doesn't have ground, so maybe I should switch to a proper one.

dvoytik avatar Oct 26 '25 21:10 dvoytik

One with ground is recommended. The switch mode power supplies on the raspberry Pi can cause the ground of the pi to float, which could influence the comms.

kellerza avatar Oct 28 '25 19:10 kellerza