Three times the door is closed and opened. That is correct. And then you see suddenly another 3 times the door “is opened and closed” which is NOT the case.
I have this problem with wrong log items of the reed switches with several windows/doors.
(I have also this problems with C++ sketches on some controllers).
I’m using a Wemos D1 Mini for connecting the reed switches. This is for example the config which is used for the picture above (the log with the wrong state changes):
binary_sensor:
- platform: gpio
pin: D5
name: "Voordeur"
device_class: door
I use it the other way around. I have the resistor on GND and via the 3.3V switch. It will also depend on the length of the wires from the switch. Here I have about 4 m of UTP cable to esp. I have it installed on the door and I use the same system to read the gas meter. Everything works without problems and false impulses.
Maybe connections? if you are using the same reed switch and it works on your gas meter. Also maybe check your cable if it is next to or crossing another power cable
Yes, the length and cross-section of the wire can affect it (greater wire resistance and voltage drop)
You can try replacing the resistor with a smaller value. For example 4k7 or something similar.
Okay but what about the cable. Somebody adviced me to have the thinnest cable available. But before I try the smaller resistor and the filter are those alarm cables always a good plan to use?
In any case, I would recommend the largest cross-section that you can afford due to the installation.
It is not a good idea to lay it parallel to the AC power lines.
Thin cable is not good. The advice should have been thicker is better but remember thicker cost more and you don’t want to thick.
@pepe59 said he uses UTP cable (Ethernet cable). normally it is 0.22 mm2 and twisted. My understanding is that twisted helps with induction of other voltages. So at 4m away it could be ok.
@VDRainer is using telephone cable and it probably twisted as well at 10m. Normally telephone is 0.5mm2 but suggested his is 0.6mm2.
twisted may help and they are normally twisted in pairs.
I use UTP cable as I already wrote. Due to the false pulses you have, it is clear that some voltage from another distribution is being induced into your cable or your GPIO is floating at low/high levels
Try using the thicker twisted cable and try to keep it away from power cables especially if it is parallel to the AC power lines as we have suggested. Crossing over power is not that bad but if you can keep about 150mm or 6 inches away it helps.
How far is the reed switch from the ESP? Your schematic (THANK YOU for not using Fritzing) looks good as does your code. You are likely getting induced noise on the GPIO pin. The longer the wire from the ESP, the more likely it’s going to see induced noise. A smaller pullup (4k7) might help. Wire size is irrelevant here since you are only sensing a voltage. There’s no current. Twisted pairs only suppress induced noise in a balanced pair of signal wires which you do not have. Never run low-voltage wires close to line voltage wires. You are almost guaranteed to get induced transients.
Can you wire a Wemos temporarily just a few inches from the switch? If the glitch problem goes away, it is almost certain to be the wiring.
You can probably keep your wiring and just add a simple delayed_on filter which should fix your bouncing
binary_sensor:
- platform: gpio
pin: D5
name: "Voordeur"
device_class: door
filters:
- delayed_on: 500ms # This value needs to be as low as possible but as high that there are no false-positives anymore
The door seems to go a bit over the frame. Does it get blocked by the frame so any pressure difference (by opening/closing) some other door doesn’t move this door just enough for the Reed switch to operate?