Using switches with gpio binary sensor

I am planning to use 5 magnet switches to detect if any doors or windows are open.
How shoud I wire it to the GPIO ports of my Raspberry pi?

I have seen different examples regarding where to put resistors.

The sensors high when the door is closed and breaks the circut when the door is opened.

Andreas

Using the word “Switch” here is confusing as HA uses Switch to mean light switch or control switch. I don’t know what the best language for this would be (contact/binary input)?

Several consideration for your home built alarm system.

Commercial wired alarms systems usually employ a EOL Resistor (End of Line Resistor). In theory this resistor is at the furthest extent of the wires. The reason for EOL is to allow detection a Dead Short in the wiring (resistance < 200 ohms). So there are 3 states in this design, Open, 200+ ohms closed, and <200 Ohms closed.

Another concept that commercial wired systems us are electrical isolation. If for some reason your alarm wiring shorts to household wiring it will usually blow a isolation chip rather than the entire system.

The raspberry Pi has pull-up resistor design built in so you may not need to add such circuitry.

I would suggest looking at Opto Isolation / Opto Coupler for your design. You can also mix voltage with this approach, powering your alarm circuits with 12 yet having 3.3V on the input side of the Raspberry.

http://www.peterlelie.de/raspi/qdigin/

Good Luck,
Calvin

You’re right switch is the wrong word here. What I am using is the gpio binary sensor. and you are correct that some of the gpio pins have built in resistors but not all of them.

I have a setup that is working most of the time but sometimes HA does not respond to the change in state until 2-5 seconds afther the state of the sensor has changed. Other times it is not recognized until the input has been turned on and off agian.

My wiring is

pin1 (3.3V) – 10k resisstor — gpio 17 (pin11) — magnet sensor (on/off) – ground.

The magnet sensor is not connected to any other power source than the raspberry pi and functions the same way a pushbutton does.

I use this setup for 5 gpio pins each with a 10k resistor.

I use GPIO with (2)magnetic door contacts and (4)12vdc motions detectors.
GPIO immediately reads OPEN condition (anything 800ms or more is my guess. This is enough for door switch and motions have setting to trip 2sec minimum)
“Pull Up” = “UP”
"Bouncetime = “50”
Connection is Pin>>resistor>>contact>>ground
OFF(short to ground through contact)
ON(Open circuit).
GPIO 4 (pin16) not used as I found its state was unstable and i planned to use for temp sensors