DHT sensor - Error accessing GPIO

I’ve just upgraded to 0.75.2 and transitioned over to using HomeAssistant in a docker container. Previously I’d been using a virtualenv.

However, since changing, I’ve been unable to get DHT and BH1750 sensor components to work. I get the error RuntimeError: Error accessing GPIO.. I know there was an issue with the Adafruit library in the last few updates to HomeAssistant. But GitHub is showing that it’s working as normal in the 0.75.2 build.

ps aux | grep -i homeassistant shows that homeassistant is being run as a root user via docker. So I’m guessing that there should be no issue with permissions or need to add root to the gpio group.

when you’re in a docker you have restricted access to the host system (kinda the whole point of a container)

From doing a search on Google you appear to have a few options (my docker doesn’t run on a Pi so can’t confirm)

  • add --privileged to your docker command, although this post appears to states it’s not a true solution
  • add --device=/dev/gpiomem:/dev/gpiomem to your docker command

If neither above solutions work, I’m sure someone else has experienced this and should be able to help :slight_smile:

Thanks for the suggestions. Makes sense.

After looking at this link I changed my docker-compose file to the following. However I’m still having issues.

  homeassistant:
    container_name: homeassistant
    image: homeassistant/raspberrypi3-homeassistant:0.75.2
    network_mode: "host"
    volumes:
      - /opt/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
      - /etc/letsencrypt:/etc/letsencrypt:ro
    devices:
      - /dev/gpiomem:/dev/gpiomem
      - /dev/mem:/dev/mem
    privileged: true
    restart: on-failure
    depends_on:
      mosquitto:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8123"]
      interval: 30s
      timeout: 10s
      retries: 6

thanks for sharing, what issues do you still have?

Sorry for not being clear in my last post.

It’s the same issue. I’m unable to access the GPIO from docker, despite declaring privileged: true and devices: - /dev/gpiomem:/dev/gpiomem - /dev/mem:/dev/mem in my docker-compose file. So I’m still getting the same error as before. DHT.py error is showing RuntimeError: Error accessing GPIO.and BH1750.oy error is showing as FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1'

not sure about RuntimeError: Error accessing GPIO, but FileNotFoundError: [Errno 2] No such file or directory: '/dev/i2c-1' suggests you also need to map /dev/i2c-1 in your docker-compose file

Thanks for your help. I managed to sort it out. You were right, both gpiomem and i2c-1 needed to be declared in my docker-compose file. Here’s what had to be added under the homeassistant docker:

devices:
  - /dev/gpiomem
  - /dev/i2c-1
privileged: true
1 Like