[I originally posted this in Hardware because it has to do with I2C but after working on it pretty hard I’ve come to realization that this is probably a docker issue, so I’m reposting here]
I have a custom PCB with several I2C devices (ADS7830 a/d converters, TCA8534 IO expanders, etc.) that I’d like to integrate into my system. The hardware is known working (I’m converting from OpenHAB to HA after the whole Insteon debacle). I’m running on a Pi 3B+ with Home Assistant OS 8.0.
I followed the instructions here for enabling I2C and it appears to be working:
➜ ~ ll /dev/i2c* crw------- 1 root root 89, 0 Mar 11 02:33 /dev/i2c-0 crw------- 1 root root 89, 1 Mar 11 02:33 /dev/i2c-1 crw------- 1 root root 89, 10 Mar 11 02:33 /dev/i2c-10 crw------- 1 root root 89, 11 Mar 11 02:33 /dev/i2c-11 ➜ ~ lsmod | grep i2c i2c_dev 20480 0 i2c_mux_pinctrl 16384 0 i2c_mux 16384 1 i2c_mux_pinctrl i2c_bcm2835 16384 0
My plan is to write something in AppDaemon that periodically scans the I2C devices and connects the I2C endpoints to HA objects either directly or through MQTT (is this the best approach?). Currently though I’m having trouble accessing the I2C bus from within HA using Python. For example, when I try from the Python console I get the following:
➜ python3 Python 3.9.7 (default, Nov 24 2021, 21:15:59) [GCC 10.3.1 20211027] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from smbus2 import SMBus >>> bus = SMBus(1) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.9/site-packages/smbus2/smbus2.py", line 280, in __init__ self.open(bus) File "/usr/lib/python3.9/site-packages/smbus2/smbus2.py", line 310, in open self.fd = os.open(filepath, os.O_RDWR) PermissionError: [Errno 1] Operation not permitted: '/dev/i2c-1' >>>
I get a similar error from within AppDaemon.
I thought that maybe HA had the I2C bus open but wouldn’t that increase the reference count on the i2c_dev module? Is this a protection mode issue?
Any help would be greatly appreciated.
- Turning off Protection mode on the terminal has no effect
- Tried it on a Pi4 with the same results
- On Raspian I tried having two simultaneous open i2c devices and that worked OK so it’s not a problem of HA already having the device open.
I’m fairly convinced that the host device is not being added to the container resulting in the Permission Error. I’m guessing that this is supposed to happen as a result of putting the rpi-i2c.conf file in CONFIG/modules on the boot partition. I believe that I did this correctly. Is there any way to check that this is the issue? Why didn’t it work?