core: Modbus #33872 does not work with Serial Devices

The problem

The new Modbus PR (designed to fix the broken implementation of the 0.108.3 integration), does not work with Serial Devices only TCP/IP devices.

Environment

Problem-relevant configuration.yaml

sensor:
# PLC (Cabinet Sensors)
  - platform: modbus
    scan_interval: 6
    registers:
      # Cabinet Temperature
      - name: PLC Cabinet Temperature
        hub: Skylight Controller
        unit_of_measurement: °C
        register: 0
        scale: 0.01
        precision: 2
      # Cabinet Minimum Temperature
      - name: PLC Cabinet Minimum Temperature
        hub: Skylight Controller
        unit_of_measurement: °C
        register: 1
        scale: 0.01
        precision: 2
      # Cabinet Maximum Temperature
      - name: PLC Cabinet Maximum Temperature
        hub: Skylight Controller
        unit_of_measurement: °C
        register: 2
        scale: 0.01
        precision: 2
      # Cabinet Average Daily Temperature
      - name: PLC Cabinet Daily Average Temperature
        hub: Skylight Controller
        unit_of_measurement: °C
        register: 3
        scale: 0.01
        precision: 2
      # Cabinet Minimum Daily Temperature
      - name: PLC Cabinet Minimum Daily Temperature
        hub: Skylight Controller
        unit_of_measurement: °C
        register: 25
        scale: 0.01
        precision: 2
      # Cabinet Maximum Daily Temperature
      - name: PLC Cabinet Maximum Daily Temperature
        hub: Skylight Controller
        unit_of_measurement: °C
        register: 26
        scale: 0.01
        precision: 2

      # Cabinet Humidity
      - name: PLC Cabinet Humidity
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 10
        scale: 0.01
        precision: 2
      # Cabinet Minimum Humidity
      - name: PLC Cabinet Minimum Humidity
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 11
        scale: 0.01
        precision: 2
      # Cabinet Maximum Humidity
      - name: PLC Cabinet Maximum Humidity
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 12
        scale: 0.01
        precision: 2
      # Cabinet Average Daily Humidity
      - name: PLC Cabinet Daily Average Humidity
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 13
        scale: 0.01
        precision: 2
      # Cabinet Minimum Daily Humidity
      - name: PLC Cabinet Minimum Daily Humidity
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 27
        scale: 0.01
        precision: 2
      # Cabinet Maximum Daily Humidity
      - name: PLC Cabinet Maximum Daily Humidity
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 28
        scale: 0.01
        precision: 2

      # Skylight (Bathroom Window Position)
      - name: Skylight Bathroom Window Position
        hub: Skylight Controller
        unit_of_measurement: Steps
        register: 20
      # Skylight (Ensuite Window Position)
      - name: Skylight Ensuite Window Position
        hub: Skylight Controller
        unit_of_measurement: Steps
        register: 21

      # Skylight (Bathroom Window Position)
      - name: 'Skylight Bathroom Position (%)'
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 22
      # Skylight (Ensuite Window Position)
      - name: 'Skylight Ensuite Position (%)'
        hub: Skylight Controller
        unit_of_measurement: '%'
        register: 23

      # Skylight (Bathroom Operation - On Time)
      - name: Skylight (Bathroom Operation - On Time)
        hub: Skylight Controller
        unit_of_measurement: s
        register: 15

      # Skylight (Ensuite Operation - On Time)
      - name: Skylight (Ensuite Operation - On Time)
        hub: Skylight Controller
        unit_of_measurement: s
        register: 16

      # Skylight (Bathroom Operation - Off Time)
      - name: Skylight (Bathroom Operation - Off Time)
        hub: Skylight Controller
        unit_of_measurement: s
        register: 17

      # Skylight (Ensuite Operation - Off Time)
      - name: Skylight (Ensuite Operation - Off Time)
        hub: Skylight Controller
        unit_of_measurement: s
        register: 18


binary_sensor:
  - platform: modbus
    scan_interval: 2
    inputs:
      - name: High High Temperature - Cabinet Alarm
        hub: Skylight Controller
        slave: 1
        address: 800
      - name: High Temperature - Cabinet Alarm
        hub: Skylight Controller
        slave: 1
        address: 801
      - name: Low Temperature - Cabinet Alarm
        hub: Skylight Controller
        slave: 1
        address: 802
      - name: High High Humidity - Cabinet Alarm
        hub: Skylight Controller
        slave: 1
        address: 816
      - name: High Humidity - Cabinet Alarm
        hub: Skylight Controller
        slave: 1
        address: 817
      - name: Low Humidity - Cabinet Alarm
        hub: Skylight Controller
        slave: 1
        address: 818
      - name: Bathroom Skylight Window - Open 
        hub: Skylight Controller
        slave: 1
        address: 145
      - name: Ensuite Skylight Window - Open 
        hub: Skylight Controller
        slave: 1
        address: 146

#Modbus TCP Connection (Siemens)
modbus:
  - name: Skylight Controller
    type: tcp
    host: 192.168.80.155
    port: 502
    delay: 0
  - name: Curtain Controller
    type: serial
    method: rtu
    port: /dev/serial/by-id/usb-www.freetronics.com_0003_95437313934351505191-if00
    baudrate: 9600
    stopbits: 1
    bytesize: 8
    parity: N
    timeout: 10

    # Modbus - PLC Cabinet
  - platform: modbus
    coils:
    # Climate Stats (Resets)
    - name: "PLC Cabinet Maximum Temperature Reset"
      hub: Skylight Controller
      slave: 1
      coil: 81
    - name: "PLC Cabinet Minimum Temperature Reset"
      hub: Skylight Controller
      slave: 1
      coil: 82
    - name: "PLC Cabinet Daily Temperature Reset"
      hub: Skylight Controller
      slave: 1
      coil: 83
    - name: "PLC Cabinet Maximum Humidity Reset"
      hub: Skylight Controller
      slave: 1
      coil: 84
    - name: "PLC Cabinet Minimum Humidity Reset"
      hub: Skylight Controller
      slave: 1
      coil: 85
    - name: "PLC Cabinet Daily Humidity Reset"
      hub: Skylight Controller
      slave: 1
      coil: 86
    - name: "PLC Cabinet Maximum Daily Temperature Reset"
      hub: Skylight Controller
      slave: 1
      coil: 881
    - name: "PLC Cabinet Minimum Daily Temperature Reset"
      hub: Skylight Controller
      slave: 1
      coil: 882
    - name: "PLC Cabinet Maximum Daily Humidity Reset"
      hub: Skylight Controller
      slave: 1
      coil: 883
    - name: "PLC Cabinet Minimum Daily Humidity Reset"
      hub: Skylight Controller
      slave: 1
      coil: 884

      # Skylight Control
    - name: "PLC Cabinet Service Mode (Remote Activate)"
      hub: Skylight Controller
      slave: 1
      coil: 97

    - name: "Skylight Control - All UP"
      hub: Skylight Controller
      slave: 1
      coil: 98

    - name: "Skylight Control - All Down"
      hub: Skylight Controller
      slave: 1
      coil: 98

      # Individual Skylight Control
    - name: "Skylight Control - Bathroom UP"
      hub: Skylight Controller
      slave: 1
      coil: 113

    - name: "Skylight Control - Bathroom Down"
      hub: Skylight Controller
      slave: 1
      coil: 114

    - name: "Skylight Control - Ensuite UP"
      hub: Skylight Controller
      slave: 1
      coil: 115

    - name: "Skylight Control - Ensuite Down"
      hub: Skylight Controller
      slave: 1
      coil: 116

      # Skylight Time Set
    - name: "Skylight Control - Ensuite On Time Set"
      hub: Skylight Controller
      slave: 1
      coil: 130

    - name: "Skylight Control - Ensuite Off Time Set"
      hub: Skylight Controller
      slave: 1
      coil: 132

    - name: "Skylight Control - Bathroom On Time Set"
      hub: Skylight Controller
      slave: 1
      coil: 129

    - name: "Skylight Control - Bathroom Off Time Set"
      hub: Skylight Controller
      slave: 1
      coil: 131

    - name: " Bedroom Curtain - UP"
      hub: Curtain Controller
      slave: 1
      coil: 0

    - name: " Bedroom Curtain - Down"
      hub: Curtain Controller
      slave: 1
      coil: 1

    - name: " Bedroom Curtain - Stop"
      hub: Curtain Controller
      slave: 1
      coil: 2

Traceback/Error logs

Log Details (WARNING)
Logger: homeassistant.helpers.entity
Source: __main__.py:342
First occurred: 4:22:43 AM (36 occurrences)
Last logged: 4:29:24 AM

Update of switch.bedroom_curtain_up is taking over 10 seconds
Update of switch.bedroom_curtain_down is taking over 10 seconds
Update of switch.bedroom_curtain_stop is taking over 10 seconds

Additional information

Debug Log: https://paste.ubuntu.com/p/M4Y9xNjYxn/

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 26 (13 by maintainers)

Most upvoted comments

And more in logs:

Logger: homeassistant.setup
Source: components/modbus/__init__.py:207
First occurred: 12:26:50 PM (1 occurrences)
Last logged: 12:26:50 PM

Error during setup of component modbus
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 171, in _async_setup_component
    hass, processed_config
  File "/usr/src/homeassistant/homeassistant/components/modbus/__init__.py", line 139, in async_setup
    await hass.async_add_executor_job(start_modbus)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/modbus/__init__.py", line 111, in start_modbus
    client.setup()
  File "/usr/src/homeassistant/homeassistant/components/modbus/__init__.py", line 207, in setup
    loop=self._loop,
  File "/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/serial.py", line 75, in __new__
    yieldable = factory_class(framer=framer, port=port, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/factory/serial.py", line 104, in async_io_factory
    client = AsyncioModbusSerialClient(port, proto_cls, framer, loop, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/asyncio/__init__.py", line 689, in __init__
    self._connected_event = asyncio.Event()
  File "/usr/local/lib/python3.7/asyncio/locks.py", line 249, in __init__
    self._loop = events.get_event_loop()
  File "/usr/local/lib/python3.7/asyncio/events.py", line 644, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'SyncWorker_12'.

update to 0.108.5

`WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed

ERROR (MainThread) [homeassistant.setup] Error during setup of component modbus

Traceback (most recent call last):

File “/usr/src/homeassistant/homeassistant/setup.py”, line 171, in _async_setup_component hass, processed_config

File “/usr/src/homeassistant/homeassistant/components/modbus/init.py”, line 139, in async_setup await hass.async_add_executor_job(start_modbus)

File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run result = self.fn(*self.args, **self.kwargs)

File “/usr/src/homeassistant/homeassistant/components/modbus/init.py”, line 111, in start_modbus client.setup()

File “/usr/src/homeassistant/homeassistant/components/modbus/init.py”, line 207, in setup loop=self._loop,

File “/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/serial.py”, line 75, in new yieldable = factory_class(framer=framer, port=port, **kwargs)

File “/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/factory/serial.py”, line 104, in async_io_factory client = AsyncioModbusSerialClient(port, proto_cls, framer, loop, **kwargs)

File “/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/asyncio/init.py”, line 689, in init self._connected_event = asyncio.Event()

File “/usr/local/lib/python3.7/asyncio/locks.py”, line 249, in init self._loop = events.get_event_loop()

File “/usr/local/lib/python3.7/asyncio/events.py”, line 644, in get_event_loop % threading.current_thread().name)

RuntimeError: There is no current event loop in thread ‘SyncWorker_3’.

ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform modbus.sensor: Unable to set up component.`

and image

I hope the above PR solves the issue.

@thehaxxa you have a big configuration, before merging the PR I would really like to hear if it works for you. Thanks in advance.

Of course the more that test the PR, the more secure we can be that the issue is gone.

update to 0.108.5

`WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed

ERROR (MainThread) [homeassistant.setup] Error during setup of component modbus

Traceback (most recent call last):

File “/usr/src/homeassistant/homeassistant/setup.py”, line 171, in _async_setup_component hass, processed_config

File “/usr/src/homeassistant/homeassistant/components/modbus/init.py”, line 139, in async_setup await hass.async_add_executor_job(start_modbus)

File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run result = self.fn(*self.args, **self.kwargs)

File “/usr/src/homeassistant/homeassistant/components/modbus/init.py”, line 111, in start_modbus client.setup()

File “/usr/src/homeassistant/homeassistant/components/modbus/init.py”, line 207, in setup loop=self._loop,

File “/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/serial.py”, line 75, in new yieldable = factory_class(framer=framer, port=port, **kwargs)

File “/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/factory/serial.py”, line 104, in async_io_factory client = AsyncioModbusSerialClient(port, proto_cls, framer, loop, **kwargs)

File “/usr/local/lib/python3.7/site-packages/pymodbus/client/asynchronous/asyncio/init.py”, line 689, in init self._connected_event = asyncio.Event()

File “/usr/local/lib/python3.7/asyncio/locks.py”, line 249, in init self._loop = events.get_event_loop()

File “/usr/local/lib/python3.7/asyncio/events.py”, line 644, in get_event_loop % threading.current_thread().name)

RuntimeError: There is no current event loop in thread ‘SyncWorker_3’.

ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform modbus.sensor: Unable to set up component.`

and image

The same log on HA started 0.108.0 and continues till last 0.108.5

I support. Home Assistant 0.108.4, during the initialization of modbus RTU, the Home Assistant service crashes and there is no access to the site. We are waiting for corrections 😃

I have this error: 2020-04-13_16-04-29