Best way to integrate several magnetic door switches

Yep, I’ll change the friendly names to reference the door once I have it all installed.

I used these Din rail mount terminals. I 3D printed my base and took the terminal board off the din rail mount then screwed it to my 3D printed board.

1 Like

Hi there @bphillips921! I’ve been eagerly following your advice on the reed switches and I bought everything you mentioned and tried to wire up everything as you showed.

Some context: I bought a home roughly a year ago and it came with a disabled alarm system. I tested it and apparently it was working, sensors included.

I replaced the old DSC alarm panel with a ESP32 with ESPhome and an optocoupler. I wired as you suggested in another thread, 1+ to hot wire from adapter, then jumper wires between positives on the “outside” of the opto coupler. I connected one of the legs of the reed switch on the negative on the optocoupler and another leg on the distributor you linked to the GND (or negative) of the adapter. 3.3v, ground and GPIO wires on the “inside” of the optocoupler.

The problem is… nothing works! I open windows and doors and nothing changes on ESPhome. I checked the optocoupler and all LEDs are always turned off. If I use a jumper wire I can make them light up… Should I plug the positive (or hot wire) into the reed switch instead? I’m not an expert at all, just a regular software guy here, trying to get my head around this :slight_smile:

Thanks for the detailed posts - helped a lot!

Can you post a picture of your Optocoupler wiring? That might help me visualize how you wired it.

Do you have an electrical tester you can use to test the reed switch? Make sure it is switching from open to close based on the door/window being open or closed.

Hi Brad,

I’ve got my door se so working without the opto, but now I’m trying to add it. I tried to follow your wiring but I must have it wrong.

Here’s what I’ve got. Two pins are in the ground on the opto. When I plug in the ESP32 to the power, the opto doesn’t light up.

Thoughts?

Your opto board is a 12v input and 3.3 output, the ESP board shouldn’t be connected to the 12v side of the opto board at all. Use the 3.3v out and the gnd pins on the ESP and connect those to the gnd and vcc on the 3.3v side of the opto. Then connect the “o1” on the 3.3v side of the opto to any GPIO pin on the ESP.

On the 12v side of the opto, hook the + line from any external 12v power source to the 1+ terminal. Then hook either wire from your Reed switch to the 1- terminal on the 12v side of the opto. The other Reed switch wire connects to the - wire on your external 12v power supply.

The Reed switch opening and closing will connect/disconnect the 12v power feed to the opto. That’s how it detects the Reed switch. If the opto receives a 12v signal the door is open, if not its closed, or vice-versa

Got it (and wired it up). That makes so much more sense! I had read the comment above about separate power sources for the opto and the esp32. Now it makes more sense. I also thought I had bought the 3.3v version of the board. Whoops.

I’ve been reading but really struggling to understand how this works. I was missing the two sides, different power sources, and then basically one to one in to out. (meaning +1 and -1 to o1, so I’m assuming +2 and -2 to 02 to another pin on the esp32).

One last question. I assume that all the other reed switch wires that are connected to the negative on the 12v power are wired together?

Sorry for the slow reply.

Correct, connect one side of every reed switch the the negative on the 12V power supply. Connect the other wire from each reed switch to a separate negative input on the 12v side of the opto. You need to “daisy chain” the positive from the power supply to each positive input on the 12v side of the opto

Hi Brad,

How have you got on with wiring directly to the GPIO pins? Have you had much trouble with interference or false positives?

I’m in a similar situation to you and trying to plan my wiring

I ended up using an octocoupler between the door sensors and the ESP32. It’s been working great.

More info

Thanks Brad, thats a fantastic write-up

I’m very new to this and trying to get my head around it. At the moment I have my ESP32-WROOM plugged in via USB, I have one end of my reed to the GPIO pin and the other to GND. In the code
pull-up = true. This works fine in HA, and I can add a second reed switch to another pin with them both going to GND.

Is this how you wired it without the optocoupler? I have seen some tutorials using the 3.3v pin on the ESP too but unsure why

Yep, that’s how to wire it without the optocoupler.

I don’t quite understand why you have a x3 terminal block distribution module then?

You have two cables coming from each terminal to the ESP (presumably GPIO and GND) and a third cable jumping from one terminal to the next.

Would you mind explaining the wiring for me?

A proper schematic (where have you heard this before) would answer a LOT of questions. A pretty Fritzing picture or a photograph is almost always absolutely worthless.

I’m not sure which x3 terminal block you are referring to. Was there a picture of a x3 terminal block in my smart home build thread?

Sorry should have been more specific. This one here:

IMG_7424
IMG_7423

I ended up ditching that setup. That’s what I would have used if not using the optocoupler. The optocoupler replaced that terminal board.

I had that terminal board set up with each of those looped wires connected to GND on the ESP32. Each long wire went to a GPIO. That way each 3x terminal could connect two sensors. I just doubled up the ground wire into the middle terminal.

1 Like

Ah gotcha, that makes sense now. Thanks Brad I appreciate your time and explanation

Hey there Brad

I’ve been reading this topic for almost two months now.
I’m on the exact same spot as you, need a solution for an in house alarm system witch would integrate with home assistant. I’m also building at the moment and I’m on the feeding lines stage.

I’m not very keen on electronics, but a close friend will help me.

Do you have more in depth pics and info of your current setup with the octocoupler?

Thanks in advance, and thanks for sharing

Yep, I ended up doing a write up on my smart home build here

This post goes over the wiring of the optocouplers for the magnetic switches.

3 Likes

Thank you very much!!

That the reading shall continue!! :smiley: