Unable to access GPIO running Home Assistant in Docker on Raspberry Pi

Hi,

I am currently running Home Assistant in Docker using an image from https://hub.docker.com/r/homeassistant/home-assistant/ (v0.68.1) on a Raspberry Pi 3.

I have connected a DHT22 temperature and humidity sensor to the GPIO’s of the RasPi, but can’t get Home Assistant to read values from it. In my configuration.yaml I have added the following entry:

sensor:
  - platform: yr
  - platform: dht
    sensor: DHT22
    pin: 4
    monitored_conditions:
      - temperature
      - humidity

The error log of home assistant tells me, that there is an error accessing GPIO.

dht: Error on device update!

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 244, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 327, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/dht.py", line 125, in update
    self.dht_client.update()
  File "/usr/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 319, in wrapper
    result = method(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/dht.py", line 160, in update
    self.sensor, self.pin)
  File "/usr/lib/python3.6/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/usr/lib/python3.6/site-packages/Adafruit_DHT/common.py", line 81, in read
    return platform.read(sensor, pin)
  File "/usr/lib/python3.6/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
    raise RuntimeError('Error accessing GPIO.')
RuntimeError: Error accessing GPIO.

On a normal Raspbian install this error usually occurs due to the user running home assistant not being in the GPIO group. The GPIO group in turn has access to /dev/gpiomem, which is needed to access the GPIO pins.

I tried giving access to the Docker container running home assistant by giving it access to /dev/gpiomem and by running it in privileged mode. by adding the following entries to my docker-compose.yaml.

..
volumes:
  ..
  - /dev/mem:/dev/mem
..
privileged: true
..

Neither of them resolved my problem.

Any idea to debug this problem would be appreciated.
Kind regards

That’s not the same as /dev/gpiomem is it?

I thought it was /sys/class/gpio

1 Like

Thank you! Your comment lead me to doublecheck my config again.

I had appened privileged: true option to the wrong container. Adding this option allowed me to access the gpio pins without adding any volumes.

/dev/mem was another suggestion I found over the internet. Without using privileged: true no combination of mounting /dev/mem, /dev/gpiomem nor sys/class/gpio solved the problem for me.

1 Like

How did you run this image https://hub.docker.com/r/homeassistant/home-assistant/ (v0.68.1) on a Raspberry Pi 3?
I’m trying run it, but i received the error message:
pi@raspberrypi:~/homeassistant $ docker-compose up
home-assistant is up-to-date
Attaching to home-assistant
home-assistant | standard_init_linux.go:190: exec user process caused “exec format error”

Could you help me?

Thanks

You can’t run that image. You need the image for the Raspberry Pi 3. The one you are trying to run is for x86_64 architecture