Illustration: Door reed sensor on Raspberry Pi with phone notifications

AI-generated illustration

Updated 24 October 2026 By Emmanuel SAUVAGE

Door reed sensor on Raspberry Pi with phone notifications

Wire a magnetic door contact to GPIO, push alerts via ntfy and optional Home Assistant MQTT discovery—gpiozero on Pi 4 and Pi 5.

Also available in French.

Know when the front door, shed or cupboard opens: a two-wire reed switch needs no sensor battery— the Pi detects open/close. This script sends ntfy push (free, open source) and optionally publishes a door entity in Home Assistant via MQTT.

Goal

  • Detect open and close.
  • Push on open (or only when open too long—see below).
  • Optional MQTT binary sensor in HA.

Time, level, parts

TimeLevelBudget
~45 minBeginnerReed switch is inexpensive—check retailers

Reed (normally open, closes with magnet): UK · US

Wiring

Internal pull-up—no external resistor.

ReedPi (physical)
Wire 111 (GPIO17)
Wire 29 (GND)

Door closed = magnet near = contact closed = GPIO low. Never apply external voltage to the reed line.

Pi prep

Same venv pattern as our other Pi sensor guides (Bookworm, gpiozero + lgpio):

sudo apt update
sudo apt install -y python3-venv python3-gpiozero python3-lgpio
mkdir -p ~/capteurs && cd ~/capteurs
python3 -m venv --system-site-packages venv
source venv/bin/activate
pip install paho-mqtt   # if using HA

ntfy: install the app, subscribe to a long random topic on ntfy.sh (public topics are readable if guessed) or self-host. Set NTFY_URL=https://ntfy.sh/your-secret-topic.

Script: porte_reed_notification.py.

Home Assistant (optional)

Mosquitto + MQTT integration; dedicated user; discovery creates binary_sensor door entity.

Smarter alert: open too long

Instead of every open, notify only if open 5 minutes:

alias: Front door left open
triggers:
  - trigger: state
    entity_id: binary_sensor.raspberry_pi_door_front_door
    to: "on"
    for: "00:05:00"
actions:
  - action: notify.notify
    data:
      message: "Front door open for 5 minutes."

Run the script without NTFY_URL if you only want this HA automation.

systemd

porte-reed.service with Environment=NTFY_URL=... and MQTT_HOST=... — enable on boot.

Troubleshooting

  • Inverted logic: swap when_pressed / when_released for normally-closed reeds.
  • Double alerts: increase bounce_time to 0.2–0.3 s.
  • No push: curl -d test https://ntfy.sh/your-topic from the Pi.

Sources: gpiozero Button · ntfy publish · HA MQTT binary sensor.

Also: garage door ESP32 · PIR motion.

All smart-home guides

Have a question about this guide or need advice? Ask us here

Torn between two models or stuck on a build? Drop us a line and we will get back to you by email.