Binary sensor do not return to 'off' after physical button is pressed

I have this automation for my doorbell.
The script.doorbell is firing fine, but it seems like when pressing the physical button attached the binary sensor it stays in state on for 30% of my tests.

EDIT: I use the LILYGO® TTGO T-Camera ESP32 WROVER, which has a physical button soldered to the PCB, to which I have soldered wires to extend the switch to my physical doorbell button on the wall.

When short-cutting the wires the effect of pushing the button, both on the PCB and on my wall, is triggered. This works great. Somehow the state of the binary_sensor.doorbell_button gets stuck in its on state once in awhile.

How can I prevent that? Can I set the value to off at the end of the automation?

Also it seems I must push the physical button for quite a long time, like push, hold, let go (fractional seconds of course) and not as one would expect; push, let go.

Would the new mode: single have something to do here?

automation:
  - alias: Doorbell
    trigger:
      - platform: state
        entity_id: binary_sensor.doorbell_button
        to: 'on'
    mode: single
    action:
      - service: script.doorbell
      - service: notify.notify
        data:
          title: Main door
          message: Who rang?
          data:
            attachment:
              content-type: jpeg
            push:
              category: camera
            entity_id: camera.ringeapparat_camera
      - delay:     ## the delay of 10 seconds, prevents this automation from being ran more often than only once every 10 seconds. 
          seconds: 10

There has been an issue open about the unreliability of the gpio binary sensor for quite some time:

I have not tried it (I moved on to another solution before this was available) but others report that the integration replacement works well. Unfortunately merging this into the core seems to have stalled.

Get it in this post:

1 Like

I appreciate you quick answer, @tom_l.
I might have described my case in a wrong way; this may not be related to GPIO

I use the LILYGO® TTGO T-Camera ESP32 WROVER, which has a physical button soldered to the PCB, to which I have soldered wires to extend the switch to my physical doorbell button on the wall.

When short-cutting the wires the effect of pushing the button, both on the PCB and on my wall, is triggered. This works great. Somehow the state of the binary_sensor.doorbell_button gets stuck in its on state once in awhile.