Garage Door Sensor Misreading While Open

I have a garage door controller built using an ESP32 and ESPHome. It’s a very basic design using a normally closed reed switch. The problem is that when the door is open, the sensor will periodically report the door closing for a fraction of a second, and then opening again. Happens a few times a minute. When the door is actually closed, it only reports closed, and does not bounce.

Wiring is: GPIO18 > Reed Switch > Ground

binary_sensor:
  - platform: gpio
    name: ${disp_name} Reed1
    pin: 
      number: GPIO18
      mode: INPUT_PULLUP
    filters:
      - delayed_on: 500ms
      - delayed_off: 500ms
    id: reed_switch1
    internal: true

Is there anything wrong with this configuration? I don’t think I’ve got a bad connection - if I did, I’d expect it to also have issues when the door is closed.

How long are the cables to the reed switch?

If they are long then they act as an antenna picking up all sorts of RFI.

When your reed switch is shorted to ground this is not an issue, as all the RFI conducts to ground.

When your reed switch is open the pullup is a relatively high impedance (~50K Ohm), so the voltage fluctuates.

Solution: Add a 0.1uF capacitor from the GPIO to ground. This will conduct away high frequencies. You could also add a lower value physical pull-up resistor (~1K Ohm).

Alternate solution: move the ESP close to the reed switch so the cables are less then 30cm / 1 foot.

Using shielded twisted pair cable may also help. Ground the shield at one end only.

Raising that delayed_off to 1s should “resolve” it.
Good suggestions in post above would resolve it at hardware level.

How long are the cables to the reed switch?

They’re long. Maybe 15 feet or so. It seemed easiest at the time to mount a little box above the garage door opener, and run cable to the door for the sensor, so that’s what I did.

I added a .1uF capacitor across the reed switch, and that seems to have done the trick. Thanks!

I would work better if you put the capacitor

i.e. at the ESP end, not the reed switch end.

Between gnd and weakly pulled up gpio.
Interesting…:open_mouth:

Sorry, I realize that was confusing. I meant electrically speaking. The capacitor is in the box with the ESP32. Both the reed switch and the capacitor have one leg connected to the GPIO, and one to ground. So in that sense, the capacitor is connected “across” the reed switch. But it’s physically connected to the GPIO.

1 Like