I am running Home Assistant inside a (the official) docker container on a Raspberry Pi 3B+. The operating system is Ubuntu 20.04 for Raspberry Pi.
I have connected a HTU21D temperature/moisture sensor via the i2c bus.
The sensor shows up under the expected address:
I’m not entirely sure which user runs the docker process, so I added the user under which i created/started the docker container to the i2c group.
I passed the i2c device to the docker container with " --device /dev/i2c-1 " and added " - platform: htu21d " to the sensor section in my configuration.yaml.
i haven’t really found a solution - but a workaround.
Some other threads suggest, that the i2c library used by HA is the problem.
(see https://community.home-assistant.io/t/htu21d-on-raspberry-pi/33132)
Some of the threads which discuss similar behaviour are a couple years old and there has not been any fix since - so I looked for an alternative solution.
I then created a cron job which runs above sample program every minute and writes the output to a textfile which I then passed through to my docker container.
I then created a command_line sensor which reads the content of the file.
After slightly rewriting the output of the sample program to output a json format, everything now works fine.