I have been using a reed switch connected to pin GPIO39 of a Wemos S2 Mini ESP32, functioning as a door sensor for a garage side entrance. It is this kind of reed switch:
This the Yaml code for the sensor:
binary_sensor:
- platform: gpio
pin:
number: GPIO39
mode:
input: true
pullup: true
name: ${friendly_name} Door contact
device_class: door
This has been working fine for at least half a year or so.
But since a few days the door sensor was broken somehow: while the door was closed the sensor was showing the door to be open but intermittently changing status open/closed.
Troubleshooting learned that the reed switch itself, the wiring soldering joints and the cabling are still perfectly fine, so it looks like this problem is being caused by the ESP unit itself.
The reed switch was connected to the GPIO39 and GND pins, with no external pull-up resistor, but using the ESP internal pull-up resistor only.
When I changed the door sensor to the GPIO18 and GND pins, that appeared to be working fine again.
But when I again added a binary_sensor
to the GPIO39 pin the problem was back again for that pin. And even without the reed switch being connected at all to the ESP the Door sensor status was changing frequently when configured for the GPIO39 pin.
This are some samples from a log:
[21:14:53][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state ON
[21:14:53][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state OFF
[21:15:03][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state ON
[21:15:03][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state OFF
[21:15:14][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state ON
[21:15:14][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state OFF
[21:15:34][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state ON
[21:15:34][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state OFF
[21:15:34][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state ON
[21:15:34][D][binary_sensor:036]: 'S2V10-01 Door contact': Sending state OFF
The status was going to ON and then immediately to OFF again.
As a test, with the reed switch still disconnected, I then added a delayed_on
filter to that sensor, and that appeared to solve the problem by then:
binary_sensor:
- platform: gpio
pin:
number: GPIO39
mode:
input: true
pullup: true
name: ${friendly_name} Door contact
device_class: door
filters:
- delayed_on: 100ms
However, some hours and reboots later this binary_sensor
on pin GPIO39 is now not functioning at all anymore: the status stays at OFF (Closed) constantly, without anything connected to GPIO39.
As a test I then also added a similar binary_sensor
to GPIO40, again without connecting anything to this pin, and that sensor as expected gives a constant status of ON (Open):
binary_sensor:
- platform: gpio
pin:
number: GPIO18
mode:
input: true
pullup: true
name: ${friendly_name} Door contact
device_class: door
# filters:
# - delayed_on: 100ms
- platform: gpio
pin:
number: GPIO39
mode:
input: true
pullup: true
name: ${friendly_name} Door Test GPIO39
device_class: door
- platform: gpio
pin:
number: GPIO40
mode:
input: true
pullup: true
name: ${friendly_name} Door Test GPIO40
device_class: door
So it looks like the GPIO39 bus functioning is broken somehow, initially causing a kind of internal debouncing, and then dying completely? Is that possible in silicon?
Being a security feature that has to be tamper proof, this type of reed switch is a normally open switch, which means that when the door is closed the switch is closed and a small current is flowing through it.
And since the door is closed most of the time, this current is flowing most of the time.
According to the Datasheet the ESP32-S2 has 45 kΩ pull-up resistors internally, so with a voltage of 3.3 V this current is 73 µA.
So can it be that this almost constantly flowing small current has damaged this ESP bus?
Or is there another possible cause for this problem?
ESP’s being rather cheap devices, can this be seen as normal degradation?
Can it be a bad surface mount soldering of the ESP chip on the PCB?
Any ideas about a possible cause and suggestions to improve this set-up?
As far as I can find it, this is not recommended anywhere in the online write-ups about reed switches, but should I add an external pull-up resistor, and if so, which resistance value?