Rpi_gpio platform does not work, please help me (Solved)

Hi all,
I’ve tried a simple example following the home assistant documentation (https://www.home-assistant.io/integrations/rpi_gpio/)
I wrote this code

# Example configuration.yaml entry
binary_sensor:
  - platform: rpi_gpio
    ports:
      11: PIR Office
      12: PIR Bedroom

in configuration.yaml
but when I check the configuration, i do not get neither the message ok, the configuration is ok, nor the message: the configuration is wrong.
each switch or sensor I try to create appling the rpi_gpio platform will give me as result the impossibility to check the configration and also restarting the switch/sensor is not created.
I’m running ha in docker, core version, on rpi4 with raspbian lite.
some one could help me?

Can you access the Raspian OS command line, via ssh, or terminal? If so run:

sudo  raspi-config > 5 Interfacing options 

and enable GPIO use, would be one thing to check
for reference: https://www.raspberrypi.org/documentation/configuration/raspi-config.md
Also make sure binary_sensor only appears once in your configuration.yaml, worth a try.

Hi,
thanks for your answer, very helpfull seems that the problem is in the GPIO configuration, The GPIO service was not installed, I’ve installed the GPIO with the following command:
sudo apt-get update
sudo apt-get install pigpio
and it is running as system service
sudo systemctl enable pigpiod.service
sudo systemctl start pigpiod.service
when I check the status with the command pi@raspberrypi:~ $ sudo systemctl status pigpiod
I get the following info:
● pigpiod.service - Pigpio daemon
Loaded: loaded (/etc/systemd/system/pigpiod.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/pigpiod.service.d
└─public.conf
Active: active (running) since Sun 2021-02-14 01:37:00 CET; 1min 37s ago
Main PID: 352 (pigpiod)
Tasks: 4 (limit: 4915)
CGroup: /system.slice/pigpiod.service
└─352 /usr/bin/pigpiod

Feb 14 01:37:00 raspberrypi systemd[1]: Starting Pigpio daemon…
Feb 14 01:37:00 raspberrypi systemd[1]: Started Pigpio daemon.

but the problem in HA is not solved, do you have other suggestions?

So did you check the two things I suggested?

yes, I did.
I think the problem is in the GPIO configuration because the pigpio service was not installed but I’ve installed the pigpio and the problem is still there.

I looked at your original post again. when you say you running Raspian Lite, do you mean Buster, should be for RPi4?
A couple other things to check, make sure rpi.gpio is installed, it should be

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi.gpio

Make sure you reboot the pi after GPIO/pigpio changes, then restart HA
If still no luck, can you share your configuration.yaml, edit out any personal details.

Hi Kdem, thanks for your support,
I tried with :

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi.gpio

as you suggested but it does not work, now I would try to instal raspbian pi os full and perform some test, in order to exclude hw problems.

when you say you running Raspian Lite, do you mean Buster, should be for RPi4?

Yes, is the official distributuion for Pi4, I got it trough raspberry pi manager, I mean this version:

Following my configuration yaml:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:


#Include files
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml

homeassistant:
#Include packages
  packages: !include_dir_named packages
#Include customized entities
  customize: !include customize.yaml


# Attivazione Logger
logger:
  default: critical
  logs:
    homeassistant.components.http: warning


#Configurazione HACS
hacs:
  token: !secret github_token

#CONFIGURAZIONE TELEGARM
telegram_bot:
  - platform: polling
    api_key: **********
    allowed_chat_ids:
      - **********
      - **********

notify:
  - name: luca
    platform: telegram
    chat_id: **********
    
  - name: ornella
    platform: telegram
    chat_id: **********
    
  - name: famiglia
    platform: group
    services:
      - service: luca
      - service: ornella
 
    
#FINE CONFIGURAZIONE TELEGARM    

# SESIONE SENSORI

###GARBAGE COLLECTION### 
garbage_collection:
  sensors:
  - name: Umido # Each week on Tuesday, Thursday, Saturday
    frequency: "weekly"
    collection_days: 
    - mon
    - wed
    - fri
  - name: Carta e Tetrapack # Each week on Tuesday
    frequency: "weekly"
    collection_days: 
    - mon
  - name: Plastica # Each week on Friday
    frequency: "weekly"
    collection_days: 
    - thu
  - name: Vetro_e_lattine # Each week on Friday
    frequency: "weekly"
    collection_days: 
    - thu
  - name: Secco # Each week on Tuesday, Friday
    frequency: "weekly"
    collection_days: 
    - mon
    - thu
    
###FINE GARBAGE COLLECTION###

###################Configurazione per gestione plancia#######################
input_select:
    floorplan_floor:
        name: The select floor to show when viewing the floorplan.
        options:
            - "1st Floor"
            - "2nd Floor"
        initial: "1st Floor"
        icon: mdi:floor-plan 
#Input select per attivare e disattivare le notifiche telegram relative al componente garbage collector    
    notification_garbage_luca:
        name: Attiva/disattiva le notifiche relative alla raccolta differenziata
        options:
            - "Enabled"
            - "Disable"
        initial: "Enabled"

    notification_garbage_ornella:
        name: Attiva/disattiva le notifiche relative alla raccolta differenziata
        options:
            - "Enabled"
            - "Disable"
        initial: "Enabled"




      
######################################################################
######################DATABASE MANAGEMENT#############################
######################################################################
recorder:
  purge_keep_days: 7
  exclude:
    domains:
      - sensor
      - automation
      - script
  include:
    entities:
# PI Info sensors
      - sensor.cpu_temperature_filtered
      - sensor.disk_use_percent_filtered
      - sensor.memory_free_filtered
      - sensor.memory_use_filtered
      - sensor.processor_use_percent_filtered
# PI Sensori di temperatura
      - sensor.external_temperature
#Tado
    #Temperatura
      - sensor.soggiorno_temperature
      - sensor.cucina_temperature
    #Umidità
      - sensor.soggiorno_humidity
      - sensor.cucina_humidity
#Piante MiFlora
      - sensor.camelia_moisture
#Bticino Living Now
      - sensor.lavatrice_power
      - sensor.asciugatrice_power
#      - sensor.din_power
#      - sensor.potenza_istantanea_filtered


################################################################################
##########                  Google assistant                 ###################
##########                 TTS & Media Player                ###################  
################################################################################
google_assistant:
  project_id: home-assistant-8ac1e
  service_account: !include DomoticLuca-9c2fff04025b.json
  exposed_domains:
    - binary_sensor


#Text to speech
tts:
  - platform: google_translate
    service_name: google_say
    language: 'it'


################################################################################
##########                      MiFlora                      ###################
##########                   Plant Camelia                   ###################  
################################################################################ 
plant:
  camelia:
    sensors:
      moisture: sensor.camelia_moisture
      battery: sensor.camelia_battery
      temperature: sensor.camelia_temperature
      conductivity: sensor.camelia_conductivity
      brightness: sensor.camelia_light_intensity
    min_moisture: 15
    max_moisture: 60
    min_battery: 17
    min_conductivity: 350
    max_conductivity: 2000
    min_temperature: 0
    max_temperature: 35
    min_brightness: 3700
    max_brightness: 95000

####################################################################
                                                                   #
######## ########  ######  ########                                #
   ##    ##       ##    ##    ##                                   #
   ##    ##       ##          ##                                   #
   ##    ######    ######     ##                                   #
   ##    ##             ##    ##                                   #
   ##    ##       ##    ##    ##                                   #
   ##    ########  ######     ##                                   #
                                                                   #
####################################################################


#>BOLEAN 
input_boolean:
    dummy_sensor:
        name: Input to test
        icon: mdi:ceiling-light
        
################################################################################
##########                      Dieta Luca                   ###################
##########                    Binary Sensor                  ###################  
################################################################################ 
binary_sensor:     
  - platform: template
    sensors:
      dieta_luca:
        friendly_name: dieta Luca
        value_template: >-
          {% if is_state('binary_sensor.dieta_luca', 'on') %}
          on
          {% else %}
          off
          {% endif %}
          
          
################################################################################
##########                   Stato Lavatrice                 ###################
##########                    Binary Sensor                  ###################  
################################################################################ 
          

  - platform: template
    sensors:
      stato_operativo_elettrodomestico:
        friendly_name: "Stato Operativo Lavatrice"
        value_template: "{{ states('sensor.lavatrice_power')|int > 0 }}"
        device_class: power
        delay_on:
          seconds: 30
        delay_off:
          minutes: 2

################################################################################
##########                 Stato Asciugatrice                ###################
##########                    Binary Sensor                  ###################  
################################################################################ 
          

  - platform: template
    sensors:
      stato_operativo_elettrodomestico:
        friendly_name: "Stato Operativo Asciugatrice"
        value_template: "{{ states('sensor.asciugatrice_power')|int > 0 }}"
        device_class: power
        delay_on:
          seconds: 30
        delay_off:
          minutes: 2
          
switch:
  - platform: rpi_gpio
    ports:
      18: Fan SHIM   

UPDATE: I’ve reinstalled Home Assistant in venv instead of docker but the problem is still there, I’ve tried to chnge the status of GPIO trough piton with a simple scrip:
‘’’

from RPi import GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.OUT)
while (True):
    GPIO.output(21, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(21, GPIO.LOW)
    time.sleep(1)

and the GPIO works well so the problem is in home assistant but I don’t know how to fix it…
do you have any suggestions?
Reply

ShareBookmarkFlag

So, now when you restart HA, in your venv , does the config checker run to completion? Are there any errors in the log after it restarts?

in Venv there are no errors in the config check but the switch is not created. so I can’t manage the GPIO trough home assistant

do you think could be worth try with “assio os” in order to understand if the problem is related to raspbian?

how about the log, Configuration (on left panel) Logs, anything in there?

none that I remember,(unfortunatelly when I’ve re-installed I forgot to activate the DNS service) and now I’ve no access to homeassistant because I’m out of home, but I’ll check later when I’ll back at home.
really thanks for your effort in helping me.

One more thing, when you set up your venv did you add whatever user you are to the GPIO group, you won’t have access otherwise.
Before you go to that trouble, try commenting out a bunch of your configuration, to simplify it, especially the config splitting for packages, and !includes, try it and if it works, you can put stuff back slowly and troubleshoot.

One more thing, when you set up your venv did you add whatever user you are to the GPIO group, you won’t have access otherwise.

No, I didn’t. I’ll try this asap.

Before you go to that trouble, try commenting out a bunch of your configuration, to simplify it, especially the config splitting for packages, and !includes, try it and if it works, you can put stuff back slowly and troubleshoot.

I’ve done it, but the problem appears also if I add to the configuration.yaml just the code related to the creation of the switch with the platform rpi_gpio

Hi,
just to don’t make you confuse because I’m jumping from an installation to another, I’ve tried to reinstall also ther docker with the following configuration:

  • Raspian 32bit full (from the pi site)
  • docker with the last version of Home Assistant core.
  • New configuration yaml
    with this fresh installation I’ve added to the configuration yaml a binary sensor suggested in the examples of home assistant documentation.
    I got this error:

Error handling request

17:25:24 – components/rpi_gpio/init.py (ERROR) - il messaggio si è verificato per la prima volta alle 17:23:53 e compare 2 volte

Error doing job: Task exception was never retrieved

17:21:22 – components/rpi_gpio/init.py (ERROR)

Error setting up integration binary_sensor - received exception

17:21:22 – components/rpi_gpio/init.py (ERROR)

So I am more familiar with venv, but the issue may be your docker container does not have direct access to the host, and since GPIO are right at kernel level, they need this. Thats why Pi user has root access. I would start here: https://stackoverflow.com/questions/30059784/docker-access-to-raspberry-pi-gpio-pins

1 Like

One more question, what version of Python are you running? Configuration > info> python version

One more question, what version of Python are you running? Configuration > info> python version

in docker I’m running the version 3.8.7 in raspbian I’m running the vesion 3.8.6

So I am more familiar with venv, but the issue may be your docker container does not have direct access to the host, and since GPIO are right at kernel level, they need this. Thats why Pi user has root access. I would start here: Docker Access to Raspberry Pi GPIO Pins - Stack Overflow

Thanks to your support I solved the problem, it was related to the permission, for the moment I solved running Docker with the “–privileged” option, for sure exist a more “secure” options and I’ll try to refine the command in order to give to docker just the needed permission for GPIO instead of root permissions.
But just for future user this command works:

docker run --init -d --name="home-assistant" --privileged -e "TZ=Europe/Rome" -v /home/homeassistant/.homeassistant:/config --net=host --restart unless-stopped homeassistant/raspberrypi4-homeassistant:stable

–privileged this option give to docker the priveldged permission, .please, pay attention in giving root privileges

1 Like