IO PI Plus stops working after home assistant error
The IO Pi Plus is a 32 channel MCP23017 GPIO expander for the Raspberry Pi
17/06/2020
Posted by:
home_builder
I hope this post founds you well.
I'm struggling to get IO PI Plus up and running with home assistant. I'm able to get it running independently, but wi hass some library issue apears that freezes i2c interface. Any hints on troubleshooting libraries would be great.
Here is how to reproduce:
I’m using the homes assistant configuration below.
switch:
- platform: mcp23017
i2c_address: 0x20
pins:
1: Light1
3: Light3
5: Light5
7: Light7
9: Light9
11: Light11
13: Light13
15: Light15
Environment used:
RPI 3 B+
IO PI Plus expander
HomeAssitant 0.110.70 - installed into venv
I2C configured
After a fresh start i can found I2C addresses (displayed instantly <1s)
(homeassistant) homeassistant@raspberrypi:/srv/homeassistant $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: 20 21 – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -
can also successfully run my test python script controlling IO PI Plus with a relay board. After starting ./hass from I2c pins are not detected and I get an error in the log.
> Logger: homeassistant.components.switch
> Source: components/mcp23017/switch.py:42
> Integration: Switch ([documentation](https://www.home-assistant.io/integrations/switch), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+switch%22))
> First occurred: 10:32:47 AM (1 occurrences)
> Last logged: 10:32:47 AM
>
> Error while setting up mcp23017 platform for switch
>
> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/adafruit_bus_device/i2c_device.py", line 184, in __probe_for_device self.i2c.writeto(self.device_address, b"") File "/usr/local/lib/python3.7/site-packages/busio.py", line 86, in writeto return self._i2c.writeto(address, buffer, stop=stop) File "/usr/local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 38, in writeto self._i2c_bus.write_bytes(address, buffer[start:end]) File "/usr/local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 308, in write_bytes self._device.write(buf) TimeoutError: [Errno 110] Operation timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/adafruit_bus_device/i2c_device.py", line 190, in __probe_for_device self.i2c.readfrom_into(self.device_address, result) File "/usr/local/lib/python3.7/site-packages/busio.py", line 76, in readfrom_into return self._i2c.readfrom_into(address, buffer, stop=stop) File "/usr/local/lib/python3.7/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 44, in readfrom_into readin = self._i2c_bus.read_bytes(address, end-start) File "/usr/local/lib/python3.7/site-packages/Adafruit_PureIO/smbus.py", line 179, in read_bytes return self._device.read(number) TimeoutError: [Errno 110] Operation timed out During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT) File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() 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/mcp23017/switch.py", line 42, in setup_platform mcp = MCP23017(i2c, address=i2c_address) File "/usr/local/lib/python3.7/site-packages/adafruit_mcp230xx/mcp23017.py", line 64, in __init__ super().__init__(i2c, address) File "/usr/local/lib/python3.7/site-packages/adafruit_mcp230xx/mcp230xx.py", line 48, in __init__ self._device = i2c_device.I2CDevice(i2c, address) File "/usr/local/lib/python3.7/site-packages/adafruit_bus_device/i2c_device.py", line 69, in __init__ self.__probe_for_device() File "/usr/local/lib/python3.7/site-packages/adafruit_bus_device/i2c_device.py", line 192, in __probe_for_device raise ValueError("No I2C device at address: %x" % self.device_address) ValueError: No I2C device at address: 20
After that momentI2C interface also gets stuck even when when homeassistant is shutdown (now discovery takes >10s)
homeassistant@raspberrypi:/srv/homeassistant $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – -- – -- – -- – -- – -- – -- –
10: – -- – -- – -- – -- – -- – -- – -- – --
20: – -- – -- – -- – -- – -- – -- – -- – --
30: – -- – -- – -- – -- – -- – -- – -- – --
40: – -- – -- – -- – -- – -- – -- – -- – --
50: – -- – -- – -- – -- – -- – -- – -- – --
60: – -- – -- – -- – -- – -- – -- – -- – --
70: – -- – -- – -- – --
Also a tutorial that worked before, stops working…
(homeassistant) homeassistant@raspberrypi:/srv/homeassistant $ python3 /home/pi/src/tutorial/tutorial2.py
Traceback (most recent call last):
File "/home/pi/src/tutorial/tutorial2.py", line 4, in bus = IOPi(0x20)
File "/srv/homeassistant/lib/python3.7/site-packages/IOPi/IOPi.py", line 110, in __init__ self.__bus.write_byte_data(self.__ioaddress, self.IOCON, self.__conf)
File "/srv/homeassistant/lib/python3.7/site-packages/smbus2/smbus2.py", line 434, in write_byte_data ioctl(self.fd, I2C_SMBUS, msg) OSError: [Errno 121] Remote I/O error
Obvioulsy there is some library conflict issue. Any hints for troubleshooting?
thank you
17/06/2020
Posted by:
andrew
I tried setting up a fresh install of Raspbian Linux, installed the 0.110.70 version of Home Assistant in a virtual environment and used the configuration that you posted above.
On my installation, everything appears to be working correctly. Home Assistant is communicating with the IO Pi Plus and i2cdetect still works when Home Assistant is running or stopped so it does look like there is a library conflict issue on your installation as you suggested.
There was a bug fix for the mcp230xx library on the Home Assistants Github repository back on the 15th of February. If you are using an older version of the library updating to the latest version may fix the problem.
18/06/2020
Posted by:
home_builder
I had found the mentioned thread had the same symptom, but after changing the lib version to 3.9.0 it results in a different error that we see above. Are you using 3.9.0 library or latest which is 5.0.1?
- Is there a way to dump into the log the lib version during execution? I'm almost sure that some lib on the wrong path or wrong python is is getting called.
- any checklist suggested to review library versions?
18/06/2020
Posted by:
andrew
I don't have much experience with Home Assistant so I do not know how to find the lib versions during execution. You may find what you need on the official Home Assistant forum.
Do you have a spare SD card you could use to set up a clean installation of Home Assistant? If you can get it working on a clean install as I did then you can compare the libraries and configuration with your current version and find any differences that could be causing the problem.
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.