10000 Modbus Crashes on 0.108.1 using Serial · Issue #33872 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Modbus Crashes on 0.108.1 using Serial #33872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HarrisonPace opened this issue Apr 9, 2020 · 64 comments · Fixed by #34043
Closed

Modbus Crashes on 0.108.1 using Serial #33872

HarrisonPace opened this issue Apr 9, 2020 · 64 comments · Fixed by #34043
Assignees

Comments

@HarrisonPace
Copy link
Contributor

The problem

Modbus Crashes in Home Assistant 108.1 using Serial Connection.

Environment

  • Home Assistant Core release with the issue:
    0.108.1
  • Last working Home Assistant Core release (if known):
    0.107.7
  • Operating environment (Home Assistant/Supervised/Docker/venv):
    Home Assistant
  • Integration causing this issue:
    Modbus
  • Link to integration documentation on our website:
    https://www.home-assistant.io/integrations/modbus/

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

Logger: homeassistant.setup
Source: components/modbus/__init__.py:175
First occurred: 6:03:36 PM (1 occurrences)
Last logged: 6:03:36 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 103, in async_setup
    hub_collect[client_config[CONF_NAME]] = ModbusHub(client_config, hass.loop)
  File "/usr/src/homeassistant/homeassistant/components/modbus/__init__.py", line 175, in __init__
    self._config_delay = client_config[CONF_DELAY]
KeyError: 'delay'

Additional information

Different Issue to Recently fixed MODBUS issue.

@marhoy
Copy link
marhoy commented Apr 9, 2020

I'm seeing the same problem with 0.108.1, and also with the latest dev-branch.
And defining "delay" in the configuration does not solve the problem:

[delay] is an invalid option for [modbus]

janiversen added a commit to janiversen/core that referenced this issue Apr 9, 2020
CONF_DELAY was used in a serial connection, which is not
permitted.

Sometimes async_update is called after async_setup is completed,
but before event EVENT_HOMEASSISTANT_START is issued, leading to
a missing object.
@janiversen
Copy link
Member

@marhoy no delay is not permitted in a serial configuration. PR #33872 hopefully solves the issue.

MartinHjelmare pushed a commit that referenced this issue Apr 9, 2020
* solve modbus issue #33872

CONF_DELAY was used in a serial connection, which is not
permitted.

Sometimes async_update is called after async_setup is completed,
but before event EVENT_HOMEASSISTANT_START is issued, leading to
a missing object.

* resolve review comment.

Do not wait for start event, but activate pymodbus directly in
async setup.

* review 2

Remark, this does not work, async_setup hangs.

clean start_modbus() from async calls, leaving only the pymodbus
setup.

* review 2a

Moved listen_once back to start_modbus, since it is sync.
@probot-home-assistant
Copy link

Hey there @adamchengtkc, mind taking a look at this issue as its been labeled with a integration (modbus) you are listed as a codeowner for? Thanks!

@janiversen
Copy link
Member

A fix is merged on dev, and ready for testing.

@marhoy
Copy link
marhoy commented Apr 9, 2020

With the latest dev branch, I had to manually install pyserial-asyncio (should be in the manifest.json?)

But I still get the following warnings/errors:

2020-04-09 19:29:46 WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed
2020-04-09 19:29:46 ERROR (MainThread) [homeassistant.setup] Error during setup of component modbus
Traceback (most recent call last):
  File "/home/pi/core-dev/homeassistant/setup.py", line 171, in _async_setup_component
    hass, processed_config
  File "/home/pi/core-dev/homeassistant/components/modbus/__init__.py", line 139, in async_setup
    await hass.async_add_executor_job(start_modbus)
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/pi/core-dev/homeassistant/components/modbus/__init__.py", line 111, in start_modbus
    client.setup()
  File "/home/pi/core-dev/homeassistant/components/modbus/__init__.py", line 208, in setup
    loop=self._loop,
  File "/home/pi/core-dev/venv/lib/python3.7/site-packages/pymodbus/client/asynchronous/serial.py", line 75, in __new__
    yieldable = factory_class(framer=framer, port=port, **kwargs)
  File "/home/pi/core-dev/venv/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)
TypeError: __init__() got an unexpected keyword argument 'timeout'

My configuration looks like this:

default_config:

modbus:
  type: serial
  method: rtu
  port: /dev/ttyUSB0
  baudrate: 9600
  stopbits: 1
  bytesize: 8
  parity: E

@janiversen
Copy link
Member

I wonder why I did not have to install pyserial-asyncio, we have pymodbus in the manifest, but not the dependencies of that. Normally each package only list the direct dependencies. I will take a look at pymodbus.

I think you caught a real UPS, timeout is silently ignored in my test setup. I will remove it in line 208 of init.py

@janiversen
Copy link
Member

@marhoy your issue is fixed with PR #33359, feel free to grab it and update your installation.

@HarrisonPace
Copy link
Contributor Author
HarrisonPace commented Apr 9, 2020

No luck with Latest PR:

Source: components/modbus/__init__.py:208
First occurred: 2:21:01 AM (1 occurrences)
Last logged: 2:21:01 AM

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 208, 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)
TypeError: __init__() got an unexpected keyword argument 'timeout'

Subsequently:

Unable to prepare setup for platform modbus.switch: Unable to set up component.
Unable to prepare setup for platform modbus.binary_sensor: Unable to set up component.
Unable to prepare setup for platform modbus.sensor: Unable to set up component.

@janiversen
Copy link
Member

Please verify that components/modbus/init.py line 199 ++ looks like this:

            _, self._client = ClientSerial(
                schedulers.ASYNC_IO,
                method=self._config_method,
                port=self._config_port,
                baudrate=self._config_baudrate,
                stopbits=self._config_stopbits,
                bytesize=self._config_bytesize,
                parity=self._config_parity,
                loop=self._loop,
            )

NO timeout= parameter. I just checked the PR on github and it contains a removal of timeout=, so maybe you have the old version of the PR.

@HarrisonPace
Copy link
Contributor Author

Thanks, updated with new error:

Logger: homeassistant.setup
Source: components/modbus/__init__.py:207
First occurred: 4:48:00 AM (1 occurrences)
Last logged: 4:48:00 AM

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_11'.

@janiversen
Copy link
Member
janiversen commented Apr 9, 2020

hmm this looks to me as if your installation (including the fact that you had to manually install pyserial-asyncio) is somehow not updated.

Please verify with pip3 that you have the right packages installed. Or even better uninstall pymodbus, to get a fresh install.

@HarrisonPace
Copy link
Contributor Author
HarrisonPace commented Apr 9, 2020

hmm this looks to me as if your installation (including the fact that you had to manually install pyserial-asyncio) is somehow not updated.

Please verify with pip3 that you have the right packages installed. Or even better uninstall pymodbus, to get a fresh install.

I think you're confusing me with @marhoy I made no changes to my packages but just for the sake of it I uninstalled and reinstalled to no avail: (same error)

bash-5.0# pip3 install pymodbus
Collecting pymodbus
  Downloading pymodbus-2.3.0-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 1.7 MB/s
Collecting pyserial>=3.4
  Downloading pyserial-3.4-py2.py3-none-any.whl (193 kB)
     |████████████████████████████████| 193 kB 15.4 MB/s
Requirement already satisfied: six>=1.11.0 in /usr/local/lib/python3.7/site-packages (from pymodbus) (1.14.0)
ERROR: python-velbus 2.0.43 has requirement pyserial==3.3, but you'll have pyserial 3.4 which is incompatible.
ERROR: pysmarty 0.8 has requirement pymodbus==1.5.2, but you'll have pymodbus 2.3.0 which is incompatible.
ERROR: pyftdi 0.50.0 has requirement pyusb>=1.0.0, but you'll have pyusb 1.0.0b1 which is incompatible.
ERROR: nad-receiver 0.0.11 has requirement pyserial==3.2.1, but you'll have pyserial 3.4 which is incompatible.
ERROR: insteonplm 0.16.8 has requirement pyserial==3.2.0, but you'll have pyserial 3.4 which is incompatible.
ERROR: elkm1-lib 0.7.17 has requirement pytz<2019.0,>=2018.9, but you'll have pytz 2019.3 which is incompatible.
ERROR: alarmdecoder 1.13.2 has requirement pyserial==2.7, but you'll have pyserial 3.4 which is incompatible.
Installing collected packages: pyserial, pymodbus
  Attempting uninstall: pyserial
    Found existing installation: pyserial 3.1.1
    Uninstalling pyserial-3.1.1:
      Successfully uninstalled pyserial-3.1.1
Successfully installed pymodbus-2.3.0 pyserial-3.4
bash-5.0# pip3 install pyserial-asyncio
Requirement already satisfied: pyserial-asyncio in /usr/local/lib/python3.7/site-packages (0.4)
Requirement already satisfied: pyserial in /usr/local/lib/python3.7/site-packages (from pyserial-asyncio) (3.4)
bash-5.0#

@marhoy
Copy link
marhoy commented Apr 9, 2020

@janiversen To be clear about my setup. I'm:

  • pulling the latest dev-branch (latest commit d510384)
  • creating a fresh virtual environment
  • running script/setup
  • running hass -c ../config where the config-directory contains the previously mentioned configuration.yaml

Given this: I

  • have to manually install pyserial-asyncio
  • Initially get the mentioned error with the "timeout"
  • If I remove line 207 from modbus/init.py, I get the same error as @thehaxxa reports

@janiversen
Copy link
Member
janiversen commented Apr 9, 2020

@thehaxxa I was not confused, but did not direct my comment directly at @marhoy. Btw the PR is ready for you to test.

@marhoy I have no idea why pyserial-asyncio is not installed as part of pymodbus on your machine, but it should be.

If you manually need to remove line 207, then it seems you have not gotten the PR. The PR contains this removal along with a number of other changes. That PR is not yet in dev.

@hacker-cb
Copy link

@janiversen

Today I worked with dev dd7fbef I also had to install 'pyserial-asyncio' manually. 'script/setup' does not installed it.
So, seems that something is broken...

@HarrisonPace
Copy link
Contributor Author

If you manually need to remove line 207, then it seems you have not gotten the PR. The PR contains this removal along with a number of other changes

I replaced every file with the latest PR, I can confirm the same error listed as before occurs.

@marhoy
Copy link
marhoy commented Apr 9, 2020

@janiversen

Just tested with the latest dev-branch (at commit 9535dd8, which I think includes your PR?)

  • I still need to manually install pyserial-asyncio
  • I'm getting the same error as reported by @thehaxxa

balloob pushed a commit that referenced this issue Apr 10, 2020
* solve modbus issue #33872

CONF_DELAY was used in a serial connection, which is not
permitted.

Sometimes async_update is called after async_setup is completed,
but before event EVENT_HOMEASSISTANT_START is issued, leading to
a missing object.

* resolve review comment.

Do not wait for start event, but activate pymodbus directly in
async setup.

* review 2

Remark, this does not work, async_setup hangs.

clean start_modbus() from async calls, leaving only the pymodbus
setup.

* review 2a

Moved listen_once back to start_modbus, since it is sync.
@HarrisonPace
Copy link
Contributor Author

All of the PRs thus far are included in 0.108.2, which I have now upgraded to. Just confirming the same issue persists:

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_21'.

@somm15
Copy link
somm15 commented Apr 10, 2020

Hello.
I'm using Modbus serial and I have the same error as well on 0.108.2.
Debug logs don't really give more info.

@janiversen
Copy link
Member

Please add the specific line “ In HA 0.107.7 there is the correct connection options (with rtuovertcp). In HA 0.108.2 there isn't this log line.” and surely there is a line in 0.108b too but different, which would be nice to see.

@volgunov-ad
Copy link

Should I wait for the update for a couple of hours or is it better to roll back to 0.107.7? I can’t turn on the light because of this problem with serial modbus.

@janiversen
Copy link
Member

It is definitively going to take at least until tomorrow until a patch is merged, so if you want light you need to roll back.

Depending on your setup, a midway is to pick the directory components/modbus from 0.107.7 and replace it in 0.108x. That is actually how I do a lot of the regression testing.

@ghost
Copy link
ghost commented Apr 11, 2020

I updated my Home Assistant to version 0.108.3 and still have a problem. On version 0.107.7 all works perfect. Ony after update is a problem.
My Config:
modbus:
type: serial
method: rtu
port: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
baudrate: 9600
stopbits: 1
bytesize: 8
parity: N

and in logs show me this:
2020-04-11 09:28:22 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.
2020-04-11 09:28:26 WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed
2020-04-11 09:28:27 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)

Is any solution for it ?

@janiversen
Copy link
Member

For the moment only copy the components/modbus files from 0.107.7 to current or downgrade. We are working on a patch but this is a far from simple bug.

@docvipul
Copy link

copying the 0.107.7 modbus component folder to new one didn't helped. The problem still persists.

@janiversen
Copy link
Member

@docvipul then you did not copy the directory with files correctly. Version 0.107.7 has been reported by many as working because it did not have any of the async connections.

If you still get the serial connect problem as reported here, you are still running with the new version.

@janiversen
Copy link
Member

I am happy to inform you all, that I have solved the problem at hand !!!

However due to the lockdown in Spain I do not have access to my serial modbus equipment, so I have only tested that the client is created correctly (the error reported in a couple of variants here), so I hope some of you will pick PR #34043 and check if it passed into actually doing something.

I am not sure how well serial reconnect is handled, should this be a problem, then please make a new issue and attach the debug logs.

Any other new problems you might find (hope not, this one caused quite some pain to solve) please make a new issue for each, that way it is easier for me to make PRs.

Thanks in advance for helping with test and your patience.

ohhh, of course I would also like to hear if it works :-)

@HarrisonPace
Copy link
Contributor Author

So I just tested the PR and in good news the PR has stopped errors appearing in HASS Logs but in bad news none of my Modbus Serial Devices work.

New Issue has made made (relating to this issue): #34046

@janiversen
Copy link
Member

Thanks, nice to get a confirmation. Plan is to get the current PR merged, and then issue a new PR for the new issue.

@HarrisonPace
Copy link
Contributor Author

As Modbus is no longer crashing, I am closing this issue. The implementation is still broken (for serial devices) as noted in the new issue: #34046

@janiversen
Copy link
Member

Just for info, please do not close an issue, when the PR is not merged to dev. When the PR is merged, the issue will automatically be closed.

The reason for this is, that if you pull dev the issue is not closed.

@HarrisonPace HarrisonPace reopened this Apr 12, 2020
@hacker-cb
Copy link

0.108.3 modbus/serial still has error There is no current event loop in thread:

2020-04-12 17:33:48 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_5'.

@janiversen, is I need to make new issue?

@janiversen
Copy link
Member

No this issue is still open, and your error is exact this issue. There is a PR #34043 waiting to be merged that solves this issue but it turned out that there are followup issues.

If you like to beta test you can grab the files in PR #34043, which solves the connect but seems to have problems communicating. We are discussing the communication problem on issue #34046

@omellin
Copy link
omellin commented Apr 22, 2020

hello,
I still have the issue on 0.108.6. any progress on merging the fixes ? thanks a lot for your work!
I'm not too sure how to use PR but I'll investigate.

The problem

Hello team, I use the modbus integration together with a USB to UART module for more than a year to readback information from my solar charger. Everything worked fine until version 0.107.x when I jumped to the 0.108.5 and 0.108.6, the modbus integration is showing the following warning and errors and the entities are not created.

I didnt try rolling back to 0.107 yet

Environment

Rpi3B+

h armv7l
dev false
docker true
hassio true
os_name Linux
os_version 4.19.114-v7
python_version 3.7.7
timezone Europe/Paris
version 0.108.6
virtualenv false
  • Home Assistant Core release with the issue: 0.108.5
  • Last working Home Assistant Core release (if known): 0.107
  • Operating environment (Home Assistant/Supervised/Docker/venv): Hassio and I also tried venv
  • Integration causing this issue: none/modbus
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/modbus/

Problem-relevant configuration.yaml

modbus:
name: hub1
type: serial
method: rtu
port: /dev/ttyUSB0
baudrate: 115200
stopbits: 1
bytesize: 8
parity: N

sensor:

  • platform: modbus
    scan_interval: 720
    registers:
    • name: sol_panneau
      hub: hub1
      unit_of_measurement: W
      slave: 1
      register: 12546
      register_type: input
      scale: 0.01
      precision: 2

Traceback/Error logs

2020-04-22 10:06:02 WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed
2020-04-22 10:06:05 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_8'.

Additional information

@janiversen
Copy link
Member

This issue is closed, because the problem is solved. The solution is in the newest 0.108 patch release

@omellin
Copy link
omellin commented Apr 22, 2020

Hello Janiversen! thanks for fast response. I'm on 0.108.6 already and I still have the issue. Do I need to switch to the dev branch?
thanks

@janiversen
Copy link
Member

But it is NOT in 0.108.6 newest release is 0.108,7 which was made yesterday. You can always look at the release notes to see if a fix is included or not.

@somm15
Copy link
somm15 commented Apr 22, 2020

I confirmed it works on 0.108.7.
Thanks a lot for the work !

Regards,

@docvipul
Copy link

@omellin if u r still facing issues you can do this for time being:

  1. make a folder 'modbus' in your /config/custom_components folder
  2. download the 107.7 release source code from https://github.com/home-assistant/core/archive/0.107.7.zip
  3. Decompress the zip file
  4. copy all the files from core-0.107.7/homeassistant/components/modbus to your /config/custom_components/modbus folder
  5. Restart Home Assistant
    Hope this Helps :-)

@janiversen
Copy link
Member

@docvipul that is a correct way of using 0.107.7 in 0.108.* and it works unless you use one of the integrations that depend on modbus.

However it is going to be a long “for time being”, because we do not work on this issue, until we see some debug logs (from 0.108.7 or higher) showing problems.

@janiversen
Copy link
Member

btw the fix in 0.108.7 is basically that copy, hence big surprise if something works in 0.107.7 and not in 0.108.7+

@docvipul
Copy link

@janiversen we appriciate your efforts. You’re doing a great job !! Thanks.

@omellin
Copy link
omellin commented Apr 22, 2020

ok, i didnt see the update available in the supervisor so i forced "ha core update --version=0.108.7" and it works now ! thanks so much!
PS - I see version 0.108.8 in supervisor now

enter360 pushed a commit to enter360/core that referenced this issue Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

0