GPIO Configuration

Hey there.

I’m attempting to set up GPIO Sensors in my set up. They are simply momentary switches that will perform automation.

Here is my configuration:

binary_sensor:
  platform: rpi_gpio
  ports:
    16: ButtonOne
    20: ButtonTwo
    21: ButtonThree
  pull_mode: "UP"
  bouncetime: 50
  invert_logic: false

I’m getting this error message and I’m running the latest version of Raspian.

16-08-22 00:17:04 homeassistant.components.binary_sensor: Error while setting up platform rpi_gpio
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 98, in _setup_platform
    discovery_info)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/binary_sensor/rpi_gpio.py", line 32, in setup_platform
    port_name, port_num, pull_mode, bouncetime, invert_logic))
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/binary_sensor/rpi_gpio.py", line 49, in __init__
    rpi_gpio.setup_input(self._port, self._pull_mode)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/rpi_gpio.py", line 46, in setup_input
    GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP)
RuntimeError: No access to /dev/mem.  Try running as root!

Last line gives you a hint.
The user your running HA as does not have permissions to change the GPIO pins. Check that your user is in the gpio group.

Thank you for the heads up.

Is there a command that I can run in putty or terminal to allow the home assistant user access to the GPIO pins?

From what I know, the Raspian version should have access to this. I also see that its not best to give home assistant root access for security reasons.

Try this:

sudo adduser pi gpio

Thank you. This pointed me in the right direction. I used the same command but substituted the user hass.

Have a good one