Modbus Sensor not receiving data from Solar Inverter

I have connected my Solar Inverter to my Mini-PC running Windows 7-64 bti through USB cable acting as RS-232. On mini PC I am running HAOS in VM Ware. The usb device is connected to Guest OS which is HAOS. The device appears as /dev/ttyACM# in HAOS. The statistics says there is no issue with the sensor, but i receive not data.

My configuration.yaml is


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

modbus:
  - name: hub1
    message_wait_milliseconds: 250
    close_comm_on_error: false
    timeout: 10
    delay: 1
    retry_on_empty: true
    retries: 10
    type: serial
    baudrate: 9600
    bytesize: 8
    method: rtu
    parity: N
    # port: /dev/serial/by-id/usb-04e2_1410-if00
    # port: /dev/serial/by-path/pci-0000:02:00.0-usb-0:2.2:1.0
    port: /dev/ttyACM1
    stopbits: 1
    
    sensors:
        - name: load1
          data_type: int16
          scan_interval: 20
          slave: 1
          address: 213
          count: 1
          input_type: holding
          unit_of_measurement: W
          unique_id: "InverterLoad"
          device_class: power
          state_class: measurement

On this mini PC, I can connect to modbus of Solar inverter and receive data on Python script.

import pymodbus
from pymodbus.pdu import ModbusRequest
from pymodbus.client import ModbusSerialClient as ModbusClient
from pymodbus.transaction import ModbusRtuFramer

client = ModbusClient(method = 'rtu', port='COM1', stopbits = 1, bytesize = 8, parity = 'N' , baudrate= 9600)
client.connect()

# inverter mode
read = client.read_holding_registers(address=201, count=1, slave=1)
Inv_Mode = read.registers[int()]

# mains voltage
read = client.read_holding_registers(address=202, count=1, slave=1)
Mains_Volts = read.registers[int()] * 0.1

# mains frequency
read = client.read_holding_registers(address=203, count=1, slave=1)
Mains_Freq = read.registers[int()] * 0.01

# output voltage
read = client.read_holding_registers(address=205, count=1, slave=1)
Out_Volts = read.registers[int()] * 0.1

# output frequency
read = client.read_holding_registers(address=207, count=1, slave=1)
Out_Freq = read.registers[int()] * 0.01

# load on inverter in Watts
read = client.read_holding_registers(address=213, count=1, slave=1)
Inv_Load_W = read.registers[int()]

# load on inverter in VA
read = client.read_holding_registers(address=214, count=1, slave=1)
Inv_Load_VA = read.registers[int()]

# battery bank voltage
read = client.read_holding_registers(address=215, count=1, slave=1)
Bat_Volts = read.registers[int()] * 0.1

# battery bank current (to/from)
read = client.read_holding_registers(address=216, count=1, slave=1)
Bat_Amps = read.registers[int()] * 0.1

# battery bank watts (to/from)
read = client.read_holding_registers(address=217, count=1, slave=1)
Bat_Watts = read.registers[int()]

# PV Volts
read = client.read_holding_registers(address=219, count=1, slave=1)
PV_Volts = read.registers[int()] * 0.1

# PV Current
read = client.read_holding_registers(address=220, count=1, slave=1)
PV_Amps = read.registers[int()] * 0.1

# PV Watts
read = client.read_holding_registers(address=223, count=1, slave=1)
PV_Watts = read.registers[int()]

# load on inverter in Percentage
read = client.read_holding_registers(address=225, count=1, slave=1)
Inv_Load_Perc = read.registers[int()]

print (Inv_Mode, Mains_Volts, Mains_Freq, Out_Volts, Out_Freq, Inv_Load_W, Inv_Load_VA, Bat_Volts, Bat_Amps, Bat_Watts, PV_Volts, PV_Amps, PV_Watts, Inv_Load_Perc)

The result is

======== RESTART: C:\Users\MuServer\Documents\modbus register reading.py =======
3 234.60000000000002 49.86 230.4 49.88 275 389 48.6 6548.0 65264 23.6 0.0 2 7

Turn on debug level logging for modbus. Post the log.

The modbus error log is

Logger: homeassistant
Source: components/modbus/modbus.py:386
First occurred: 6:16:45 AM (1957 occurrences)
Last logged: 4:47:47 PM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/modbus/sensor.py", line 95, in async_update
    raw_result = await self._hub.async_pymodbus_call(
  File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 409, in async_pymodbus_call
    result = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 386, in _pymodbus_call
    result = entry.func(address, value, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/common.py", line 114, in read_holding_registers
    return self.execute(request)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 109, in execute
    return self.transaction.execute(request)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/transaction.py", line 194, in execute
    response, last_exception = self._retry_transaction(retries, "empty", request, expected_response_length, full=full)
  File "/usr/local/lib/python3.10/site-packages/pymodbus/transaction.py", line 251, in _retry_transaction
    in_waiting = self.client._in_waiting()
  File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 674, in _in_waiting
    in_waiting = ("in_waiting" if hasattr(
  File "/usr/local/lib/python3.10/site-packages/serial/serialposix.py", line 549, in in_waiting
    s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
OSError: [Errno 5] I/O error

Looks like there are problems with the VMWare pass-thru for the serial port. You can try ssh into HASSOS and running your python test program. That would verify it’s a mapping issue.

ok i will check. thanks alot

also that on windows 7 host the usb appears as COM#, and on another system with Ubuntu 22 the usb appears as /dev/ttyUSB# on host, but on both systems the usb appears as /dev/ttyACM# on guest HAOS

The python script runs good on other system with Ubuntu 22 where usb appears as /dev/ttyUSB#. I was unable to run python script in HAOS through SSH terminal as I am new to HAOS as well as Python language. I have removed the VM layer by installing HAOS-generic-x86-64 image to a USB drive and ran HAOS directly on the other system (Intel Xeon 2nd gen. with 8GB ram). The problem persists.

(Pymodbus: hub1: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)

sensor image1

So I did some research, the usb is Exar USB UART appearing as XR21V1410-COM# in windows 7 host (I installed XR21V1410 usb drivers and only after that python script worked) and as /dev/ttyUSB# in Ubuntu 22 host (python script worked with no additional drivers installed for usb). The usb appears as /dev/ttyACM# with-in the guest HAOS as well as HAOS running directly on PC (no VMs involved). Strange thing is that /dev/ttyACM# is in the group of audio whereas I think it should be a member of tty and dialout groups. HAOS being very light weight does not include many drivers. So I went to Exar USB UART website and they have given drivers for linux kernel 3.6 -5.11 and stated we have to first remove the CDC-ACM drivers and then install their xr_usb_serial drivers, which I am unable to do for now. Can you guide me in this process if this is the right direction to go.

You are on the right track.

Rather than passing the USB device in to VMware, you should try to pass the COM port in. The USB device is not a serial device, their USB driver creates a COM port (which emulates a serial port). Since you have the driver installed in windows and the COM port emulated, you probably can’t also run a Linux version of the driver at the same time, as now you have two drivers talking to one device.

Finally some success.

sensor image2

I had still another PC (Lenovo-ThinkCenter-AIO) which had a native RS-232 DB9 pin port. The solar inverter has two ports, one usb and the other RS-232 (the cable provided by the solar inverter manufacturer is RJ45 to the inverter side and DB9 pin to the PC side). First ran hoas in VM and still same problem. Then ran haos directly from the usb i made earlier. Used the port /dev/ttyS0 and the sensors got working. Now I will try the same /dev/ttyS0 in VM as you suggested. Will post the resuts later on. Thanks for you advice.

1 Like

Firstly let the usb remain in host (appearing as COM2 on the host) and in the VM-haos guest used /dev/ttyS0, but didn’t worked. Then shutdown haos and added Serial Port to the VM-haos and mapped it to the COM2 port of the host.

Then probed the serial devices and set port to /dev/ttyS1 and sensors became live and now showing the data.

Now after months of work got success. Thanks to you. Will show you my energy dashboard when completed.

1 Like