Can't make rpi_gpio binary sensor to follow the state of GPIO input

Hi,
Asking a question for the first time in a hope that someone could be able to show me the right direction to proceed. I’m not completely noobie, have been playing with home assistant on RPi3 now around half year, but still every day learning new aspects of this environment.

I have now tried few days to make binary sensor to reflect correctly the status of 2 of my GPIO interfaces, without success. I can make the sensors appear in the UI, but sooner or later after few changes in the state of GPIO interfaces my binary sensors end up showing wrong state. Even after having waited quite some time those states won’t end up to update to correct value in HA. I have tried both without and with pull-up resistors (10k towards +3.3V and 1k towards GPIO interface itself, in between the resistors I connect to ground to control each GPIO input), both without success. I have also tried other ports (17&18) but no difference in the behaviour.

My configuration.yaml looks as following:

binary_sensor:
  platform: rpi_gpio
  ports:
    22: AV-Gad armed (22)
    23: TeleControl alarm (23)
  pull_mode: "UP"
  invert_logic: False
  bouncetime: 50

As an example, using

sudo gpio readall

I get following output:

but despite that my HA UI is showing following states:

Despite I can see both inputs as 0 on command line, HA showing one of them in “on” state and one in “off”.

Any idea what might be wrong in my setup? I’m running version 0.44.1. Thanks for your help.

Anyone able to help?

Did you solve this?
Are you sure you used the right pin names?
If I understand your problem correctly you connected to Physical pin 15 and 16. Which are BCM pin 22 and 23. However the RPI_GPIO package use the Name. So this means pins GPIO 3 and GPIO 4.
Can you try pin 3 and 4 instead in your configuration.yaml?

No I wasn’t able to solve it.
I’m pretty sure I used correct pins, as RPi was able to detect let’s say 80% of times when the state of the input changed (and nothing else connected to RPi pins). As my use case is to connect RPi to my burglar alarm system, it is not enough that it works just 80% of time. Thus I gave up.

I saw elsewhere other people having exactly the same issue. Attached to those messages there were guidance to use python scripts to communicate with GPIOs, as those are 100% reliable (and instead of using HA GPIO sensors one to use command line sensors on RPi side, together with frequent polling of such python scripts). That’s why I completely gave up. If I ever come to try this again I’ll take the python-path to fulfill my needs, as my experiences were as they were.

I did some tests yesterday. I have a button connected to physical pin connector pin 15. Using Port = 22 (with binary_sensor) works good for me. So the naming should indeed be fine. So far it is working as expected.

binary_sensor:
  - platform: rpi_gpio
    ports:       
      # 22 = connector pin 15 on RPI_B+
      22: Deurbel
    pull_mode: UP

For the trigger I am using from: to: as I am only testing for a change.

- alias: Doorbell pressed    
  trigger:                
    - platform: state     
      entity_id: binary_sensor.deurbel
      from: "on"                      
      to: "off"                       
  action:    .....

So far so good.

1 Like