I have a binary sensor set up for a GPIO pin on a Raspberry Pi. It works fine most of the time, but randomly, Home Assistant misses state transitions and the sensor gets stuck in the wrong state. This causes problems for the rest of my automations that need to know whether my garage door is open or not. When the sensor is in the wrong state, I have confirmed on the command line using the gpio tool that the pin is indeed in the expected state. Is there a way to fix this, or a workaround to poll RPi for the correct state?
binary_sensor:
- platform: rpi_gpio
ports:
13: GarageDoorSensor
pull_mode: "DOWN"
automation:
- alias: Publish garage door state change - open
trigger:
platform: state
entity_id: binary_sensor.garagedoorsensor
from: 'on'
to: 'off'
action:
service: script.notify_mqtt
data:
target: "garage_door"
message: "open"
After having downgraded HA from 64bit to 32bit hoping to use rpi_gpio (GPIO is not supported on 64bit), I find that GPIO’s as “binary_sensor”, even on HA 32bit, are not reliable and therefor not usable. State transitions are not accurately captured or followed by HA, where HA state is often opposite of actual GPIO state.
switch:
- platform: rpi_gpio
ports:
2: Alarm Annunciator
binary_sensor:
- platform: rpi_gpio
ports:
5: Front Door Bell
6: Carport Door Bell
7: Living Room PIR
10: Living Room Window
11: Bedroom 1 Window
12: Bedroom 2 Window
13: Bedroom 3 Window
14: Bathroom Window
15: Kitchen Window
16: Front Door
17: Sliding Door
18: Carport Door
pull_mode: 'UP'
invert_logic: true
Applying a capacitor between GND and GPIO pin of binary sensor solves the problem. I putted a 1uF electrolytic capacitor or a SMD capacitor and with both works very stabil. Before that I had unreliable responses as well.
You keep saying this and I keep telling you that will only work in specific cases. i.e. where you don’t have a lot of GPIOs to monitor and where HA is not busy with lots of other stuff.
After seeing that there are problems on the Home Assistant I tried with openHABian and encountered the same problems. I try to say that this is the good solution to which I have not found an answer on this forum and maybe it is suitable for others. I assure you that my configuration is not simple, my example with a single sensor was for everyone to understand that it does not take something special to reach the same result as me.