Hi there, I’m trawling through posts and getting no joy.
Long term I’m looking to use opto-couplers to link my 12V home alarm PIRs to the GPIO ports of my Pi and I was just wanting to get the s/w working while I wait on the hardware to arrive. My plan was to just test the GPIO pins to 3.3V or GND and hope to see the toggle in HA to then get some automations setup.
Don’t use the Pi’s GPIO inputs. Even if you get it working the Home Assistant GPIO integration is unreliable. This issue has been open for over three years:
There are alternatives. My favourite is using another pi running this: Expose the Raspberry Pi GPIO pins over MQTT. It is configured with yaml and has been running reliably for me as long as that issue has been open.
Search the forum for Flyte’s MQTT GPIO software. I have made many posts on this.
Actually as you are running the core version (instead of Home Assistant OS) you should be able to run it on the same pi as home assistant. Though I have never tired this.
2021-01-31 15:40:44,850 mqtt_gpio (INFO): Startup
2021-01-31 15:40:45,100 mqtt_gpio (INFO): Connected to the MQTT broker with protocol v3.1.1.
2021-01-31 15:40:45,110 mqtt_gpio (INFO): Polling: Input 'doorbell' state changed to True
2021-01-31 15:40:45,120 mqtt_gpio (INFO): Polling: Input 'PIRLanding' state changed to True
But mosquitto.log
1612107644: Socket error on client pi-mqtt-gpio-e83249bd3ba79932e16fb1fb5100dafade9954c2, disconnecting.
1612107645: New connection from 192.168.0.31 on port 1883.
1612107645: Socket error on client pi-mqtt-gpio-e83249bd3ba79932e16fb1fb5100dafade9954c2, disconnecting.
1612107645: New client connected from 192.168.0.31 as pi-mqtt-gpio-e83249bd3ba79932e16fb1fb5100dafade9954c2 (c0, k60, u'DVES_USER').
1612107665: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
Should I be worried?
Now with my LED light strips I needed to send a command via Tasmota console to make the devices visible to the MQTT Integration I have in HA (something like SetOption19 1)
Im guessing their is an equivalent - any ideas / pointers ?
Hi,
I’m new to HA and Raspberry Pi and just set up HA (core 2023.8.2) on a Pi 4 model B. Just found a way to read the GPIO of the Pi directly from HA:
Install libgpiod in the Pi: go to HA Terminal tab, run command: “apk add libgpiod”. You then should be able to run commands like “gpioget 0 21” (get the state of GPIO21 on chip0). However mine gives error: “error reading GPIO values. Operation not permitted”. I think this is something to do with the terminal user doesn’t have permission to read/write the ports. However the command in HA sensor would works.
After restarting I have a sensor in HA that I can use to automate other tasks, though not sure how responsive this is, properly not instantaneous but for me this is good enough, and quite simple as well.
I found other solutions using the command “cat /sys/class/gpio/gpio21/value”, or - platform: rpi_gpio don’t work any more. Apparently the newer Raspberry Pi 4 with new OS has discontinued this hardware access method.