PI GPIO Sensor not always updating

I am using HA and getting to enjoy it more and more. After using a number of MQTT devices, I am now experimenting with the PI’s GPIO pins.

I am using GPIO pin 17 as input. I have confirmed that wiring is correct by creating the following simple phyton script in jessie to read input.

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    input_state = GPIO.input(17)
    if input_state == False:
        print('On')
        time.sleep(0.2)
    else:
        print ('Off')

Output is correct. Depending on input, a message saying On or Off is displayed as expected.

However, these states are not reflected in HA.

The GPIO input is defined as a sensor (see below), and this shows on the dashboard.

binary_sensor:
  - platform: rpi_gpio
    ports:
      17: IntruderAlarm

It does change state occasionally, but more often than not, it fails to update.

Looks like a HA issue, but being a relative newbie to HA I cannot be so sure.

Did anyone come across this issue or can offer some advice please?

I am having the same issue on latest HA and pi3 running jessie.

the gpio function is working as expected, the HA dashboard is showing the sensor but stat is not changing when the GPIO is fired

I have this in my config

  • platform: rpi_gpio
    name: piled
    ports:
    18 led
    invert_logic: true
    bouncetime: 1000

*updated my config to above, now I see the changes but it is “twitchy” i run the py script to light the led and it take half a second to register on the HA dashboad, then it flips back and fourth from on to off very rapidly while the py script has exited and cleaned up GPIO

no errors in the logs either

well i spoke to soon, missed the log files,

My connection was bad so it was going up and down, just not enough for the LED to light.

my config is as follows

  • platform: rpi_gpio
    name: piled
    ports:
    18: piled
    invert_logic: false
    bouncetime: 1000
    pull_mode: “down”

this works correctly and the dash is almost immediate