Garage Door Controller for Home Assistant

Dual-Bay Garage Door Local Controller for Home Assistant

This project builds a low voltage (5v) garage control unit to be integrated into Home Assistant. (Although there is always AI to draw on for projects like this; a proven, working reference provides the confidence to make the time & money investment!). The ESP32 based control unit easily interfaces with Home Assistant to locally control two garage roller doors, track their physical open/closed states via reed switches, and monitor bay occupancy using overhead ultrasonic sensors. This provides an ideal platform to reliably automate opening on arrival etc.

The project assumes moderate DIY skills - mounting of various sensors and wires to wall and brackets, assembly and soldering of wires and connection pins, flashing of an ESP32 using ESPHome and creating dashboard cards in Home Assistant.

The project requires some 3D printed components to mount 2 sensors (links to files provided). These will need to be sourced or made.

Key Features

  • 100% Local Control: Integrated directly into Home Assistant via the ESPHome native API.
  • Zero Boot-Glitch Safeguard: Configured so a reboot or power outage will never accidentally open your garage doors.
  • True Door State Tracking: Uses physical magnetic reed switches on the door tracks (no relying on optimistic states).
  • Bay Occupancy Detection: Overhead ultrasonic sensors detect whether a car is parked in either bay.
  • Reliable Wi-Fi Connectivity: Uses an ESP32-S3 board paired with an external 2.4GHz antenna mounted outside the project box.

Pre-Build Compatibility Check

Before purchasing any parts, verify that your garage door motors can be triggered via a simple dry-contact momentary pulse (essentially simulating a standard push-button press):

  1. Check Your Garage Motor Owner’s Manual: Look for wiring diagrams showing external accessory terminals—typically labelled OSC, PB (Push Button), WALL, SW, or COM + START/TRIG.
  2. Inspect the External Motor Control Points: Confirm that shorting those two terminals together for ~0.5 seconds opens, stops, or closes the door. (Note: This project is not suited to newer encrypted/Security+ 2.0 motors, which require a specialised serial wall button rather than simply connecting dry contacts.)

Bill of Materials

Component Qty Specification / Notes
Microcontroller 1 ESP32-S3 DevKitC-1 (N16R8) w/ IPEX + 2.4GHz External Antenna (external antenna recommended for garage use - metal surfaces deflect & block Wi-Fi signals)
Relay Module 1 5V 2-Channel Relay Board with Optocouplers (must have H/L Jumpers)
Distance Sensors 2 RCWL-1601 Ultrasonic Sensors (Must be 3.3V native logic)
Door Sensors 2 Normally Open (N/O) Magnetic Reed Switches (will need 5–10m leads - to suit your garage and intended control unit mount location)
Enclosure 1 UB3 Jiffy Box with mounting flange (130 x 67 x 44mm)
Cabling 10m (or length to suit your garage) 24AWG 4-Core Security Cable-for wiring of Ultrasonic sensors, 8m (or length to suit your garage) of 24AWG 2 core-for garage door motors external controls
Connection Plugs Approx. 50 PH2.54 Crimp Pins (allow for wastage during soldering), approx. 10 1x4 2.54mm & approx. 20 1x1 2.54mm Housings
Power Supply 1 5V 2A Power Adapter & Cable with USB-C end to suit ESP32
3D Printed Mounts — 2 x Ultrasonic Sensor Mounts & 1 x ESP32 box: (File 1, File 2)

3D Printed mounts

The Bill of Materials includes links to 3D Prints that are suitable to hold the ultrasonic sensors and contain the ESP32 board while keeping access to the board pins. Note the files linked include extra parts and alternate designs, so choose/ adapt to suit.

Hardware Mounting

Mount each ultrasonic sensor in its 3D print bracket above each car bay with the ‘eyes’ pointing downward. Attach them to lightweight brackets extending ~450mm from the wall above the roller door roll, positioned at approximately 80° from horizontal, ensuring the line-of-sight is clear of the door roll when fully opened.

Decide the mount location for the UB3 Jiffy Box control unit which will house the ESP32, Relays and external antenna, considering ultrasonic sensor and magnetic reed switch wiring paths, mains power access for the 5v adapter and Wi-Fi signal. Suggest the small wall section between the roller doors.

(Mounting of the magnetic reed switches will come later)

Wiring & Pinout Guide

Master Connection Table

ESP32-S3 Pin Target Component Target Pin / Terminal Notes
5V (V5) Relay Module Pins VCC/ DC+ Powers the 5V relay coils (Also see Critical Hardware Build Notes below)
3.3V (3V3) RCWL-1601 Pins VCC Sensors are 3.3V so can be directly connected to ESP32 board
GND Relay, Sensors, Reeds GND / DC- / Common Shared system ground rail (wires can be spliced if number of ESP32 pins available is limited)
GPIO 4 Relay Module IN1 Left Door momentary trigger
GPIO 15 Relay Module IN2 Right Door momentary trigger
GPIO 5 Bay 1 RCWL-1601 TRIG Left bay distance Trigger
GPIO 6 Bay 1 RCWL-1601 ECHO Left bay distance Echo
GPIO 7 Bay 2 RCWL-1601 TRIG Right bay distance Trigger
GPIO 8 Bay 2 RCWL-1601 ECHO Right bay distance Echo
GPIO 16 Reed Switch 1 Terminal 1 Left door state (INPUT_PULLUP)
GPIO 17 Reed Switch 2 Terminal 1 Right door state (INPUT_PULLUP)

Wiring Connections

  • At one end of the 4-core security cable, strip & lightly solder-tin each wire end, solder each wire to individual female crimp pins, use pliers to flatten/ fold the small wire clamp lugs and insert all ends into a 4-pin 2.54mm housing. Use this end of the cable as the ceiling end so the RCWL-1601 sensor can be unplugged if replacement is needed.
  • Refering to Hardware Mounting notes above; test fit and cut the length of the 4-core cable with 4 pin housing to suit distance (plus some slack) from one ultrasonic sensor location to the intended UB3 Jiffy control box location.
  • Repeat attaching crimp pins to the remaining length of 4-core, taking care to match the 4-pin holder wire colour locations to the first cable. Each garage bay should have a cable with matching 4 pin housing wire colour locations.
  • Make note of the Sensor pcb silkscreen VCC, GND, TRIG & ECHO labelling & associated 4 pin wire colours & holder orientation for later reference during final wiring connections.
  • Measure/ test-fit and cut the wires to suit for each Ultrasonic sensor, magnetic reed switch and garage motor external control to the intended UB3 Jiffy Box location, ensuring sufficient reach with some slack to play with. (Do not mount the wires or box until final soldering of pin connections is completed).
  • Drill hole in Jiffy Box lid top face for external antenna mount.
  • Drill appropriately sized holes in the box lid sides/ ends and pass through the wire ends for Ultrasonic sensors x 2, magnetic reed switches x 2, garage motor external controls x 2 and 5v USB-C power lead (elongate a hole as required).
  • Strip the wire ends, solder them to female crimp pins and fit them into 1-pin 2.54mm housings.** Check the number of ESP32 GND pins available, you may need to splice GND/ Common wires.
  • Temporarily attach the UB3 Jiffy Box lid in its intended location (masking tape etc)
  • Connect & neatly route the Ultrasonic sensor and garage motor external control wires from the sensor/ connection points to UB3 Jiffy Box temporary location.
  • Mount one magnetic reed switch to each roller door so the wired sensor will align with the separate magnet when closed. Install the sensors with leads at the lower end/ bottom of the centre-most track frames and install the separate magnets on the bottom rail of each door, so that there is an approximate 2mm gap between them which closes the circuit when the door shuts.

Relay and ESP32 Board preparation

  • Refer to the Critical Hardware Build Notes below to configure the Relay jumper switches.
  • Refer to the ESPHome YAML Configuration below to flash the ESP32 with code.
  • After flashing and while the ESP32 is powered, check the ESP32 5v pins have 5v available, refer to the Critical Hardware Build Notes.

Relay, Switch and Board Connections

Refer to the full connections mapping in the Master Connection Table above, noting the following:

  • Relay Outputs: Connect the 2-core wires from the garage door motor external controls terminals (as per Owners manual wiring diagram) to COM and NO (Normally Open) on each relay channel (there is no polarity).
  • Relay connections: The IN1 and IN2 for each Relay connect to the GPIO 4 and GPIO 15 ESP32 pins, with VCC and GND (or DC+ / DC-) Relay connecting to 5V and GND ESP32 pins.
  • Reed Switches: Wire one leg of the magnetic reed sensor to the designated GPIO (16 or 17) and the other leg to GND.
  • Ultrasonic Sensors Connect each of the 4 wires, ensuring a match of the previously noted wire colours/ Sensor pin ID to the respective ESP32 pins. Connect each VCC Sensor connection to the 3V3 ESP32 pins, and GND Sensor connection to the ESP32 GND common ground pin or splice wire.
  • ESP32 power Plug the USB-C lead into the ESP32 board USB port
  • Antenna: Fit antenna to Jiffy Box lid and clip lead to ESP32 board

When assembling all parts into the box lid, use light flexible packing foam sheet to keep the Relay & ESP32 boards from touching by wrapping each board for a loose push fit when inside the Jiffy Box lid.


Critical Hardware Build Notes

Before powering anything up, check & verify these two hardware details have been attended to:

1. Preventing Boot-Glitches (High-Level Relay Trigger)

  • The selector jumpers on the relay board should be set to the H (High-Level) position.
  • Why: During boot or a reset, ESP32-S3 GPIO pins sit in a floating, high-impedance state. If your relay is set to Low-Level (L), a floating pin can momentarily sink enough current to trigger the relay and open your garage door. In High-Level mode, the relay requires an active 3.3V signal to fire, keeping your doors safely closed during reboots.

2. Fixing the 5VN Pin on ESP32-S3 Clone Boards

Many third-party ESP32-S3 DevKitC-1 boards have pins labelled 5VN on the pcb silkscreen, signifying the 5V output pin is disconnected from the USB power rail. The 5VN pin will measure ~1.6 - 1.9V and consequently the relay’s won’t operate (the green power LED won’t light up). The fix is bridging the power jumper:

  1. Inspect the ESP32-S3 near the USB ports / 5VN pin for two small, exposed silver pads labelled IN-OUT or 5V-EN.
  2. Apply a small blob of solder across these two pads to bridge them.
  3. Once bridged, USB 5V power flows directly to the 5VN pin, delivering a solid 5V to power the relay coils.

ESPHome YAML Configuration

How to flash the ESP32 using ESPHome is assumed knowledge (noting that the Home Assistant ESPHome add-on is very user-friendly!). A few software highlights in this config:

  • Staggered Ultrasonic Polling: Left bay polls every 5s and right bay polls every 7s so the two ultrasonic sensors don’t fire simultaneously and interfere with each other.
  • Ultrasonic Errors & Smoothing: If a sensor misses an echo or is out of range (NaN), a lambda filter maps it to 3.5m (empty floor distance) before running it through a median and sliding-window moving average filter to eliminate false occupancy triggers.
  • Magnetic Reed Switch Debounce: A small 100ms delay when switching OFF or ON settles any fluctuations due to final door movements.
  • Occupancy Detection: The ultrasonic sensor is set to show a Detected state when the distance is less than 2.0m (configurable), with small delays to settle fluctuations.
  • ESP32 Responsiveness: Setting power_save_mode: NONE ensures an instant response when you hit the button in Home Assistant.

(Click below to expand the full YAML)

ESPHome Configuration (esp-garage.yaml)
# Board: ESP32-S3 DevKitC-1 (Espressif)
# Definition: definitions/boards/esp32-s3-devkitc-1/manifest.yaml

esphome:
  name: esp-garage
  friendly_name: ESP Garage

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: esp-idf
  flash_size: 16MB

psram:
  mode: octal
  speed: 80MHz

logger:
  level: DEBUG

api:
  encryption:
    key: "<your key goes here>"

ota:
  - platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: ESP Garage Fallback Hotspot
  power_save_mode: NONE

captive_portal:

sensor:
  # --- GARAGE LEFT BAY SENSOR ---
  - platform: ultrasonic
    trigger_pin: GPIO5
    echo_pin: GPIO6
    pulse_time: 10us
    name: Left Distance
    unit_of_measurement: "m"
    icon: "mdi:arrow-expand-vertical"
    update_interval: 5s
    id: left_distance
    filters:
      # 1. Catch out-of-range (NaN) immediately and map to empty floor distance (3.5m)
      - lambda: |-
          if (isnan(x)) {
            return 3.5;  
          }
          return x;
      # 2. Smooth readings with median and moving average
      - median:
          window_size: 3
          send_every: 1
          send_first_at: 1
      - sliding_window_moving_average:
          window_size: 3
          send_every: 1

  # --- GARAGE RIGHT BAY SENSOR ---
  - platform: ultrasonic
    trigger_pin: GPIO7
    echo_pin: GPIO8
    pulse_time: 10us
    name: Right Distance
    unit_of_measurement: "m"
    icon: "mdi:arrow-expand-vertical"
    update_interval: 7s            # Staggered polling to prevent acoustic cross-talk
    id: right_distance
    filters:
      # 1. Catch out-of-range (NaN) immediately and map to empty floor distance (3.5m)
      - lambda: |-
          if (isnan(x)) {
            return 3.5;  
          }
          return x;
      # 2. Smooth readings with median and moving average
      - median:
          window_size: 3
          send_every: 1
          send_first_at: 1
      - sliding_window_moving_average:
          window_size: 3
          send_every: 1

  - platform: wifi_signal
    name: WiFi Signal RSSI
    id: esp_sensor_wifi_signal

binary_sensor:
  # --- LEFT BAY OCCUPANCY ---
  - platform: template
    name: Left Occupied
    device_class: occupancy
    lambda: |-
      if (isnan(id(left_distance).state)) {
        return false;
      }
      return id(left_distance).state < 2.0;
    filters:
      - delayed_on: 3s
      - delayed_off: 5s
    icon: "mdi:car"

  # --- RIGHT BAY OCCUPANCY ---
  - platform: template
    name: Right Occupied
    device_class: occupancy
    lambda: |-
      if (isnan(id(right_distance).state)) {
        return false;
      }
      return id(right_distance).state < 2.0;
    filters:
      - delayed_on: 3s
      - delayed_off: 5s
    icon: "mdi:car"

  # --- LEFT DOOR MAGNETIC REED SWITCH ---
  - platform: gpio
    pin:
      number: GPIO16
      mode: INPUT_PULLUP
      inverted: false
    name: Left Door Position
    id: left_door_contact
    filters:
      - delayed_off: 100ms
      - delayed_on: 100ms
    device_class: garage_door

  # --- RIGHT DOOR MAGNETIC REED SWITCH ---
  - platform: gpio
    pin:
      number: GPIO17
      mode: INPUT_PULLUP
      inverted: false
    name: Right Door Position
    id: right_door_contact
    filters:
      - delayed_off: 100ms
      - delayed_on: 100ms
    device_class: garage_door

# --- RELAYS (MOMENTARY WALL-BUTTON PULSES) ---
switch:
  - platform: gpio
    pin: 
      number: GPIO4
      inverted: false # Matches High-Level (H) jumper setting
    id: left_relay
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: left_relay
    name: Left Door Relay

  - platform: gpio
    pin: 
      number: GPIO15
      inverted: false # Matches High-Level (H) jumper setting
    id: right_relay
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: right_relay
    name: Right Door Relay

# --- INTEGRATED HOME ASSISTANT GARAGE COVERS ---
cover:
  - platform: template
    name: Left Door
    id: left_door
    device_class: garage
    lambda: |-
      return id(left_door_contact).state ? COVER_OPEN : COVER_CLOSED;
    open_action:
      - switch.turn_on: left_relay
    close_action:
      - switch.turn_on: left_relay
    stop_action:
      - switch.turn_on: left_relay
    optimistic: false
    
  - platform: template
    name: Right Door
    id: right_door
    device_class: garage
    lambda: |-
      return id(right_door_contact).state ? COVER_OPEN : COVER_CLOSED;
    open_action:
      - switch.turn_on: right_relay
    close_action:
      - switch.turn_on: right_relay
    stop_action:
      - switch.turn_on: right_relay
    optimistic: false

Home Assistant Dashboard Card

Here is a clean, native Lovelace card configuration (no custom cards required) that combines the inline cover open/close tile controls with a heading badge indication of vehicle presence in the bay. Duplicate this and swap left for right to display both bays in a single card.

(Click below to expand the full YAML)

Home Assistant Garage Control Card (garage_cover.yaml)
type: entities
show_header_toggle: false
grid_options:
  columns: 12
  rows: auto
entities:
  - type: custom:hui-heading-card
    heading_style: title
    visibility:
      - condition: state
        entity: binary_sensor.garage_esp_garage_left_occupied
        state: 'on'
    badges:
      - type: entity
        show_state: true
        show_icon: true
        entity: binary_sensor.garage_esp_garage_left_occupied
        color: state
    icon: ''
  - type: custom:hui-tile-card
    entity: cover.garage_esp_garage_left_door
    name: Left Garage
    vertical: false
    features:
      - type: cover-open-close
    features_position: inline