Help with reading GPIO inputs

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:
Imgur

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:
Imgur

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.

Are you using the 64 bit home assistant image on your pi?

The gpio only works on the 32 bit image.

In answer to your question, yes I have been able to use the gpio port on a pi3b. Though it had issues. It often missed the return to low state for short pulses. That was well over a year ago and I have since moved on to the NUC image but the issue for this is still open.

Are you using the 64 bit home assistant image on your pi?

Yes, I was made aware that GPIO does not work for the 64-bit version of Hassio, so I’m using the 32-bit version.

It often missed the return to low state for short pulses.

The relay isn’t set to pulse but to constant. The circuit is closed for minutes or hours at a time, not milliseconds as a pulse, so that can’t be the issue.

I am kind of regretting switching to Hassio. I like to tinker too much for Hassio’s limitations. At least the way I understand it you are very limited in Hassio. I can’t even use pip or apt-get. I can’t install any packages or dependencies to configure some more custom stuff. Maybe I’m understanding things wrong, though.

Stumbled on this a few weeks back. Not sure if it’s relevant for your setup but sounds like it may be useful: https://microhobby.com.br/blog/2020/02/02/new-linux-kernel-5-5-new-interfaces-in-gpiolib/

This is pretty interesting but I doubt HASSIO has this new function. Many of those commands aren’t available in HASSIO. The morale of the story is that I shouldn’t have installed HASSIO because it is SO limited in what you can do with the kernel and neither should someone else unless they’re going to build the most rudimentary of Home Assistant setups.