Modbus RTU ttyUSB0 not working

Hello,
I have a Intel Nuc running HA, connected with my home network and a USB serial interface connected to my Unitronics OPLC M91.
When I test the MODBUS interface on the same usb converter in Windows, I can communicate and get data update…
If I configure it in HA, It is not working:

/config cat home-assistant.log
2022-11-07 20:47:22.206 INFO (Syncworker_2) [homeassistant.components.modbus.modbus] modbus M91 communication open
2022-11-07 20:47:23.697 DEBUG (Syncworker_3) [pymodbus.client.sync] New Transaction state 'SENDING'
2022-11-07 20:47:26.715 ERROR (SyncWorker_3) [homeassistant.components.modbus.modbus] Pymodbus: M91: Modbus Error: [Input/Output] Modbus Error: [Invalid Me
ssage] No response received, expected at least 2 bytes (0 received)
2022-11-07 20:47:42.493 DEBUG (Syncworker_4) [pymodbus.client.sync] New Transaction state 'SENDING'
2022-11-07 20:47:45.503 DEBUG (SyncWorker_4) [homeassistant.components.modbus.modbus] Pymodbus: M91: Modbus Error: [Input/Output] No Response received from
the remote unit/Unable to decode response
2022-11-07 20:48:02.493 DEBUG (Syncworker_3) [pymodbus.client.sync] New Transaction state 'SENDING'
2022-11-07 20:48:05.501 DEBUG (Syncworker 3) [homeassistant.components.modbus.modbus] Pymodbus: M91: Modbus Error: [Input/Output] No Response received from
the remote unit/Unable to decode response
2022-11-07 20:48:22.497 DEBUG (SyncWorker_4) [pymodbus.client.sync] New Transaction state 'SENDING'
2022-11-07 20:48:25.507 DEBUG (Syncworker_4) [homeassistant.components.modbus.modbus] Pymodbus: M91: Modbus Error: [Input/Output] No Response received from
the remote unit/Unable to decode response
2022-11-07 20:48:42.501 DEBUG (SyncWorker_0)
2022-11-07 20:48:45.587 DEBUG (Syncworker_0)
the remote unit/Unable to decode response
2022-11-07 20:49:02.495 ERROR (Syncworker_3) [pymodbus.client.sync] [Errno 2] could not open port /dev/ttyUSBB: [Errno 2] No such file or directory: '/dev/
ttyusie'
2822-11-07 20:49:02.585 DEBUG (Syncworker_3) [homeassistant.components.modbus.modbus] Pymodbus: M91: Modbus Error: [Connection] Failed to connect[ModbusSer
ialclient(rtu baud[38400])]
2022-11-07 20:49:22.498 ERROR (Syncworker_4) [pymodbus.client.sync] [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/
ttvUSRO'
[pymodbus.client.sync] New Transaction state 'SENDING'
[homeassistant.components.modbus.modbus] Pymodbus: M91: Modbus Error: [Input/Output] No Response received from
The device is known in Linux
→
(config
/config setserial -G -v /dev/ttyUSB[01]
/dev/ttyUSB0 uart unknown port 0x0000 irq 0 baud_base 24000000 spd_normal
My Config is: 
# modbus config
logger:
  logs:
    homeassistant.components.modbus: debug
    pymodbus.client: debug
modbus:
  - name: M91
    type: serial
    baudrate: 38400
    bytesize: 8
    method: rtu
    parity: N
    port: /dev/ttyUSB0
    stopbits: 1
    binary_sensors:
    - name: "test"
      address: 4000
      scan_interval: 20
      device_class: moving
      input_type: discrete_input

If I unplug the USB from the Nuc and connect it to my windows PC, I can communicate with the OPLC with QMODmaster.

Settings are the same: 38400,n,8,1 within the PLC software

I have no idea why the communication does not start in HA.
Restarts have no effect.

Any suggestions?
Thanks in advance
Walter

I got it working with the following settings:

  • message wait, retry on empty and not closing com on error seems to be needed.
  • slave: 1 to be sure you only ask for one bit.

The scan_interval should be > message wait x number of bits…

logger:
  logs:
    homeassistant.components.modbus: debug
    pymodbus.client: debug
modbus:
  - name: M91
    message_wait_milliseconds: 1000 
    retries: 20
    retry_on_empty: true
    close_comm_on_error: false
    type: serial
    baudrate: 38400
    bytesize: 8
    method: rtu
    parity: N
    port: /dev/ttyUSB0
    stopbits: 1
    binary_sensors:
    - name: "test"
      address: 4000
      slave: 1
      scan_interval: 20
      device_class: moving
      input_type: discrete_input
2 Likes

Some extra info, that could be of use for others:

The Modbus manual of Unitronics states that the maximum time between messages could be as low as 2ms(master-slave), so 10ms seems ok for PC-M91 communication.

In general, the time needed for one message is less than 100ms.
Using that as a rule of thumb, gives you the scan_interval, dependent on the number of messages.

It seems that the following general settings made the difference:
** retries: 20**
** retry_on_empty: true**
** close_comm_on_error: false**

# modbus config
logger:
  logs:
    homeassistant.components.modbus: debug
    pymodbus.client: debug
# modbus 38400 = 100ms/msg    
modbus:
  - name: M91
    message_wait_milliseconds: 10 
    retries: 20
    retry_on_empty: true
    close_comm_on_error: false
    type: serial
    baudrate: 38400
    bytesize: 8
    method: rtu
    parity: N
    port: /dev/ttyUSB0
    stopbits: 1
    binary_sensors:
    - name: "SS5 alarmcontact garage voor"
      address: 4043
      slave: 1
      scan_interval: 2
      device_class: moving
      input_type: coil
    delay: 1
    timeout: 3
    retries: 3
    retry_on_empty: true
    message_wait_milliseconds: 250

Just registered to say thanks for this. I just picked up a Unitronics V120 RA22 and am going to try and put it to use automating a high tunnel aka hoop house or unheated greenhouse. I was going to go with home automation components but recently started working at a factory and discovered industrial control/automation. The components are more robust and rugged than consumer versions. They use mostly Unitronics stuff at work so I figured I’d go with the same.

Still, I’d like to at least view the status of high tunnel components if nothing else and HA seems like a nice system for that and modbus seems the only way.