core: Component error: modbus - Exception importing homeassistant.components.modbus
The problem
Adding ModBus integration does not succeed and triggers the following error, blocking HA from restarting and loading it.
Component error: modbus - Exception importing homeassistant.components.modbus
Attempted to, with the same result:
- remove the TCP part and only leave the serial connector
- remove anything else but the simple modbus: line
Thanks!
What version of Home Assistant Core has the issue?
2023.1.4
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
modbus
Link to integration documentation on our website
https://www.home-assistant.io/integrations/modbus
Diagnostics information
N/A
Example YAML snippet
modbus:
- type: tcp
name: ew11
host: 192.168.4.39
port: 502
Anything in the logs that might be useful for us?
Logger: homeassistant.loader
Source: components/modbus/modbus.py:10
First occurred: 12:03:35 (17 occurrences)
Last logged: 13:18:33
Unexpected exception importing component homeassistant.components.modbus
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/loader.py", line 725, in get_component
cache[self.domain] = importlib.import_module(self.pkg_path)
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/src/homeassistant/homeassistant/components/modbus/__init__.py", line 117, in <module>
from .modbus import ModbusHub, async_modbus_setup
File "/usr/src/homeassistant/homeassistant/components/modbus/modbus.py", line 10, in <module>
from pymodbus.client.sync import (
File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 180, in <module>
class ModbusTcpClient(BaseModbusClient):
File "/usr/local/lib/python3.10/site-packages/pymodbus/client/sync.py", line 184, in ModbusTcpClient
def __init__(self, host='127.0.0.1', port=Defaults.Port,
AttributeError: type object 'Defaults' has no attribute 'Port'
Additional information
Modbus does not load regardless of the configuration parameters, which seems to be the main issue. The connection to the host that is being attempted, shall be working as per the previous experience and settings shared here . Iād assume the integration is not designed to hard fail when unable to connect to the host.
Useful to know, yet not too sure of the interactions (expecting none), is that the Huawei Solar HACS integration is running and is connecting through ModBus too, so the the issue could be:
- Default.Port not translating to a number port to bind upon 127.0.0.1,
- the host to connect to does not get fed into modbus initialization (127.0.0.1) and so is for the port,
- the default port to bind to might, for instance, be used by this third party integration and the official integration could require a setting to listen upon another port (not 502) to function, too, and establish a connection to this second host
- anything else š
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (10 by maintainers)
In October I planned to use pymodbus v3.0.2, but then we found a serious problem in the serial part, which meant the modbus integration could not use v3.0.2.
I opened a PR in the asyncio-pyserial repo but that was not responded to (and still not is) so we had to go down another route, all of this causing delays, and now finally the modbus integration is using v3.1.0 on dev, but I suspect the custom integration needs some smaller update due to some api differences between v3.0.2 and v3.1.0.