Hello, it’s me again
Problem:
I cannot for the live of me get the GPIO pins to work in Home Assistant. I feel like I’ve tried everything. ALL I NEED is an entity that will say “on” or “off” depending on the state of an output on an external device. It’s just a binary sensor. It should be simple. But it’s not, apparently.
- Hardware: RPi 3B+
- Home Assistant version: 0.118.5
- OS: HassOS 4.16
- My configuration. yaml:
binary_sensor:
- platform: rpi_gpio
ports:
4: armed_state
24: door_state
bouncetime: 50
invert_logic: false
pull_mode: down
As you can see I am trying to use GPIO 4 and 24. As far as I understand I need to use the GPIO numbering aka the BCM numbering and not the actual pin numbers and that’s what I’ve done. I’m using a Sparkfun GPIO break out board on a breadboard that has BCM numbering on it.
Now my issue is that the state never changes. They are always HIGH. Even if I rip out everything and set the pull_mode to down, it is still high. Which makes no sense to me.
This is an illustration of the circuit:
It doesn’t work.
I then thought “I don’t trust this HA integration”, and went my own way about getting the values from the actual GPIO directory on the RPi. So I unexported GPIO 4 and 24 in /sys/class/gpio and tried to read the values like this:
binary_sensor:
- platform: command_line
name: armed_state
command: "cat /sys/class/gpio/gpio4/value"
payload_off: "0"
payload_on: "1"
scan_interval: 10
- platform: command_line
name: door_state
command: "cat /sys/class/gpio/gpio24/value"
payload_off: "0"
payload_on: "1"
scan_interval: 10
I didn’t know how to set the internal resistors so I made my own pull-up/pull-down resistor circuits.
This is an illustration of that circuit:
This did not work either. The value would now finally change from constantly HIGH to floating about. It probably sounds like my circuits were wrong but I was using the EXACT SAME resistor circuit 2 days ago on my old HA installation where it worked fine. If I cat the value file like I set up the configuration.yaml to do then I can see that value is flip flopping all over the place… What is happening? Is this circuit not correct? It should be pulled down through the 10k resistor when the relay is open but it doesn’t. I feel like I’ve had an aneurysm, I don’t understand why it’s not working.
Interestingly the first binary sensor “armed_state” on GPIO 4 will flip flop like it’s floating (it probably is, but I don’t know how) but the second binary sensor “door_state” does nothing whatsoever. It never changes state. It’s constantly low. Even if I change to a pull-up resistor, it’s low. Either I broke those GPIO pins or the HA messed something up.
Has ANYONE been able to integrate a simple binary sensor into their HA? I’ve been looking for examples of people’s work and have found none. Any help would be much appreciated. I’m just about ready to jump off a bridge.