Closed HarrisonPace closed 4 years ago
As noted on discord, please update the issue by only having serial connections in your config. Once done please update config and debug log. Thanks in advance.
So after testing it seems that simply the Modbus device doesn't respond, so I garner its not been sent out correctly?
2020-04-12 12:38:48 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-12 12:38:49 WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed
2020-04-12 12:38:49 DEBUG (MainThread) [pymodbus.client.asynchronous.asyncio] Connecting.
2020-04-12 12:38:50 DEBUG (MainThread) [pymodbus.client.asynchronous.asyncio] Client connected to modbus server
2020-04-12 12:38:50 INFO (MainThread) [pymodbus.client.asynchronous.asyncio] Protocol made connection.
2020-04-12 12:38:50 INFO (MainThread) [pymodbus.client.asynchronous.asyncio] Connected to /dev/serial/by-id/usb-www.freetronics.com_0003_95437313934351505191-if00
2020-04-12 12:39:22 DEBUG (MainThread) [pymodbus.client.asynchronous.asyncio] send: 0x1 0x1 0x0 0x0 0x0 0x1 0xfd 0xca
(full logs: https://paste.ubuntu.com/p/73vYcVP4K6/ )
As discussed on Discord calling modbus.write_coil
results in the service working once every 50 or so times, thus it looks like it may be a timing issue.
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!
I have this error:
This is a closed issue, this problem is solved, however we still have a couple of other issues.
However your error look more like a configuration error.
Before 108 version no errors with configuration... And I see it not closed:
Well let me put it differently, a patch have been merged into dev for this issue...and discussions etc. are continuing in other issues.
Apart from that it is quite impossible to help you without more information like e.g. your logs and configuration.
With the following patch to pymodbus-2.3.0:
--- a/pymodbus/client/asynchronous/factory/serial.py
+++ b/pymodbus/client/asynchronous/factory/serial.py
@@ -102,8 +102,6 @@ def async_io_factory(port=None, framer=None, **kwargs):
sys.exit(1)
client = AsyncioModbusSerialClient(port, proto_cls, framer, loop, **kwargs)
- coro = client.connect()
- loop.run_until_complete(coro)
return loop, client
I'm able to create a AsyncModbusSerialClient with an already running event loop. (The above run_until_complete() fails when the provided loop is already running. And in HA, we want to use the already running HA event loop).
I can then create a test-script that creates a loop, an AsyncModbusSerialClient, handles the client.connect(), and tries to read an input register from my serial modbus device.
Problem is, it doesn't work consistently: About half of the time, it works as expected. The other times, the script just hangs inside the pymodbus rtu_framer. There seems to be (at least one) bug in the pymodbus asyncio implementation wrt. parsing the received bits.
I'm happy to send the test-script and/or debug logs from it to anyone who's interested.
I am interested.
Hi, I am using modbus with a serial port and it does not work for me either, let me know what information could help you.
@janiversen I belive this is an issue with the pymodbus library, so I've opened an issue there will all the details of my findings: https://github.com/riptideio/pymodbus/issues/500
It seems that the async support in pymodbus is flaky at best.
I appreciate your effort to update to the latest pymodbus package, but are you sure it's a good idea to also switch to the async modbus client? I haven't had any issues with the sync client.
I happen to agree with you, and will make a patch that restores the sync client, but keeps all the other changes made.
I will leave the async version committed so it is available when there are a new version of pymodbus.
A maybe better option long term, is only to use the protocol component from pymodbus and handle the socket/serial communication in the integration, which would allow us to use the parts available in core.
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 :)
The others have not reported a crash of HA, that is something very new !!
We know the modbus integration stops, but that is not HA.
It is quite ok, that you are waiting for corrections, but when you report a problem like a crash of HA, without logs or anything, do not expect a solution to your problem. A HA crash needs a new issue, because in this issue we only work to solve the serial problem, which is in the communication and not a crash.
Updated to Home Assistant 0.108.4 Same error. In logs found: Error executing script. Service not found for call_service at pos 1: Unable to find service modbus/write_register
In UI I see:
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
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
The same log on HA started 0.108.0 and continues till last 0.108.5
2020-04-16 00:44:40 WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed
2020-04-16 00:44:43 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'.
2020-04-16 00:44:49 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform modbus.sensor: Unable to set up component.
Errors in HA from 0.108.1 to 0.108.5 version.
So anyone who is having issues I recommend simply copying the 0.107.7 modbus implementation into a 0.108.x installation until this is fixed.
This method works fine, however I would recommend implementation is changed back until the serial component can be fixed or pymodbus is implemented using a different serial method in HASS. Its less than ideal to have a broken implementation across several release cycles (even if this is a result of upstream API issue).
I am preparing that as we speak.....however I want to keep the other features added, so it is not just a simple copy/paste operation. I miss updating 1 file and test before making the pr, for dome of you to test
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.
@thehaxxa you have a big configuration, before merging the PR I would really like to hear if it works for you. Thanks in advance.
All good from my side, everything is working.
I get this in my logs but everything works:
Source: __main__.py:342
First occurred: 1:22:15 PM (2 occurrences)
Last logged: 1:22:25 PM
Update of switch.bedroom_curtain_up is taking over 10 seconds
Update of switch.bedroom_curtain_down is taking over 10 seconds
Cleanup recv buffer before send: 0x54 0x55 0x20 0x43 0x75 0x72 0x74 0x61 0x69 0x6e 0x20 0x53 0x65 0x72 0x76 0x65 0x72 0xd 0xa 0x1 0x1 0x1 0x0 0x51 0x88
Connection lost. Reconnecting…
Installed version 0.108.7, ModBus RTU works with only one slave. If there are 2 or more slaves, data is read only from the first in the configuration list. If someone has more than one slave, check if it works ...
This is a closed issue. It sounds like you might have a new problem, so you need to create a new issue.
Please do not forget to add:
And of course the log from a run with logger active.
Without that we are not really able to help.
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
Traceback/Error logs
Additional information
Debug Log: https://paste.ubuntu.com/p/M4Y9xNjYxn/