Reed switch stuck on

Going around in circles again! I have a simple reed switch, monitoring a door, that's been working for several months. I noticed the door was showing as having been closed for 2 days when I know it's been open. Power cycled the ESP-wroom-32 but still showing closed when open. Pulled it apart and tested the reed OK with a multimeter. Reconnected but still stuck on.

I've tried another reed switch but still stuck on. The other weird thing is that ESP is showing as online even when it is not (ie depowered). The log says it can't connect but the ESP is still shown as online.

Suggestions gratefully accepted !

INFO ESPHome 2026.6.2
INFO Loaded validated config cache for esphome-web-q3.yaml, skipping validation.
INFO Starting log output from 192.168.1.56 using esphome API
INFO Successfully resolved esphome-web-q3 @ 192.168.1.56 in 0.000s
WARNING Can't connect to ESPHome API for esphome-web-q3 @ 192.168.1.56: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.56', port=6053))]: [Errno 113] Connect call failed ('192.168.1.56', 6053) (SocketAPIError)
INFO Trying to connect to esphome-web-q3 @ 192.168.1.56 in the background

The ESP config is :

# Garage PA door reed switch
esphome:
  name: esphome-web-q3
  friendly_name: esphome-web-q3

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    advanced:
      minimum_chip_revision: "3.0"
      sram1_as_iram: True

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "QCVRjWVNeC9WPHDCC+extm3v0Byf8Z0cTaklXwg5eJA="

ota:
  - platform: esphome
    password: "xxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-Q3 Fallback"
    password: !secret fallback_password

binary_sensor:
  - platform: gpio
    name: "Garage PA"
    pin:
      number: 16
      inverted: True
      mode:
        input: True
        pullup: True
    device_class: door
    filters:
      - delayed_off: 50ms

text_sensor:
  - platform: uptime
    name: garage pa uptime
    update_interval: 10min
    format:
      separator: " "
    
captive_portal:

Build another one?
I highly doubt we can troubleshoot this for you from here...

Sure, that's a fix. I was hoping there was some known issue with 2026.6.2 (as unlikely as that would be) or some suggestion of other evaluation to localise the problem. Thanks anyway.

Plug it into your computer running ESPHome via USB and see if you get log output when it boots up. Post the log output here, if any.

How is the reed switch wired?

You have the input pull-up enabled and the sensor inverted.

So the switch should be shorting GPIO 16 to ground when active.

Most reed switches are normally open. Meaning when the magnet is near the reed switch it closes and shorts the GPIO to ground. As your GPIO is inverted this turns the binary sensor on and the device class translates this to open.

You want the opposite of this (magnet near reed = closed), so remove the inverted: true option from your binary sensor pin configuration.

Also, don't capitalise True, it should be true.

Thanks Tom. Hmm, didn't notice the T - was working like this but fixed now.
Yes, the reed is NO. Changing to inverted: false changed the state to open but it still doesn’t change state when the magnet is beside the reed. Yet I'm certain the reed closes when the magnet approaches (as per multimeter continuity).
I'll try GPIO17 ?

Ok, action! It works on GPIO17, although unexpectedly the wrong way around. With no magnet, state is on & with magnet state is off.
I can deal with that by re-adding inverted: true

However, the reed is definitely open with no magnet, closed with magnet.

Was wired straight wire from gpio16 to one reed terminal & another wire from GND to the other reed terminal. Now same but gpio17.

With inverted: true in place, no magnet = off = open & with magnet = on = closed
And yet, with a multimeter, no magnet = open & magnet = closed

So it is changing state in ESPHome now?

Yes, changing state, having changed to gpio17. For some reason gpio16 just stopped working.

I have some thoughts, maybe helpful, maybe not.

I have used magnetic reed switches, the "raw" ones and I have found them to be finicky. They are not particularly reliable in that they get "stuck". They cannot handle much current. The orientation of the magnet relative to the switch is important (As I remember, with round magnets, the axis of the magnet should be parallel to the switch? check me on this.)

On the ESP devices, an input can go bad. A pullup resister is always advisable. Test the input with a button switch (with pull up resistor) to see if it has truly gone bad. A failure of this test indicates damage from ESD (electrostatic discharge). This kind of damage can migrate and eventually kill the device.

Sometimes erasing the device and re-flashing can resolve the issue.

Thanks, constructive suggestions.

The reed, I think, is good - works consistently when I test it with a multimeter. Testing with a switch/external pullup is a good idea - I'll do that. Reflashing is worth a try too.

ESD seems very unlikely. The board has been working for months, inside a project box attached to the wall. It only has the fully sealed reed attached & there are no power sources that could induce a current in the wires.

Thanks for the thoughts. One has to love the helpful community :slight_smile: