Project

Smart Garage Door Opener with Open/Closed State Sensing

Commercial smart garage openers cost $90 and lock you into an app that needs an account, ads, and a cloud the company will eventually shut down. This project does the same thing for $22 and reports to whatever home automation server you run. The trick is that we don't replace the garage door opener — we just pulse the same two wires the wall button uses. Whatever opener you have, ten or thirty years old, this works.

How it works

flowchart LR HA[Home Assistant
or any MQTT client] HA -->|topic: garage/cmd
payload: open/close| ESP32 Phone[Phone browser] Phone -->|HTTP /toggle| ESP32 ESP32[[ESP32]] -->|GPIO 26 HIGH
500 ms pulse| Relay Relay[Relay closes
across button wires] --> Opener[Garage Door
Opener] Reed[Reed switch
on door track] -->|GPIO 27| ESP32 ESP32 -->|topic: garage/state
open or closed| HA

The relay across the wall-button contacts is electrically identical to a person pressing the button. The reed switch reports whether the door is up or down.

Bill of materials

  • ESP32 dev board — $7
  • 5V single-channel relay module (with optoisolator) — $2
  • Reed switch (normally open) + magnet — $2
  • 5V/1A wall adapter — $4
  • Project box — $4
  • 20 m of 22 AWG wire (relay-to-opener and reed-to-ESP32) — $3

Total around $22.

Wiring

Inside the project box (mounted near the opener)

ESP32     Relay module       Garage door opener
GPIO 26 - IN
5V      - VCC
GND     - GND
          NO  - terminal 1 (push button)
          COM - terminal 2 (push button)

Reed switch (mounted on the door track)

Reed switch     ESP32
one terminal -- GND
other        -- GPIO 27 (with INPUT_PULLUP)

Identifying the wall-button terminals on your opener: there are usually two screws labeled "1" and "2" on the side of the opener motor unit. The wall button shorts them. Your relay does the same — wire NO and COM in parallel with the existing wall button wires (don't disconnect the wall button).

Firmware design

The firmware runs an MQTT client and a tiny web server in parallel. Both expose the same two endpoints: toggle (pulse the relay for 500 ms) and state (return open/closed from the reed switch). The reed switch state is published to MQTT every 30 seconds and on every change, so Home Assistant gets near-instant updates.

One safety detail: the relay must be triggered LOW. Cheap relay modules invert the logic — wiring IN HIGH energizes the coil. The firmware uses digitalWrite(RELAY_PIN, LOW) to activate. Test on the bench before connecting to the opener so you don't accidentally pulse the door while you're working on it.

Going further

  • Add a notification when the door has been open for more than 10 minutes — most people don't need this until the day they need it.
  • Use Home Assistant geofencing to auto-close the door when the last family member leaves home.
  • Add a second reed at the fully-open position so the firmware reports three states: open, closed, in-motion.

Key code: main loop

This is the heart of the firmware, taken from the working sketch. The complete file (with config template, library list, and the rest of the helpers) is around 82 lines and is included in the downloadable project package — request it via the form below.

void loop() {
if (!mqtt.connected()) mqttConnect();
    mqtt.loop();

    bool open = isDoorOpen();
    if (open != lastDoorOpen) {
        lastDoorOpen = open;
        publishState();
        Serial.printf("[reed] %s\n", open ? "OPEN" : "CLOSED");
    }
    if (millis() - lastReportMs > 30000) {
        lastReportMs = millis();
        publishState();
    }
    delay(50);
}
Project package

Get the complete project package

The article above shows the core firmware and the principles behind it. The complete project package — assembled, tested, and ready to flash — is available by email request. We send it manually, and we read every request.

  • Complete Arduino sketch (.ino) with full error handling
  • List of required libraries with version numbers
  • Printable wiring diagram (PDF)
  • Bill of materials with current part numbers
  • Build guide and troubleshooting tips
  • Configuration template (WiFi, MQTT, etc.)

We send the package by email within 24 hours, usually faster. Free, no spam, no mailing list. Your email is used once, for this reply.

Share your thoughts

Worked with this in production and have a story to share, or disagree with a tradeoff? Email us at support@mybytenest.com — we read everything.