We had a problem with leaving our garage door open. I blame our toddler and all the toddler paraphernalia we are carrying in when getting out of the car. However, if we are honest with ourselves, we are just forgetful. The first couple of times, our neighbors let us know but eventually they gave up. My parents have a garage door that automatically closes after so many minutes. So I looked for a solution for our garage door.
Off the shelf solution
We have a roller style door with a B&D motor. B&D sells a "Smartphone Control Kit", but I wasn't about to spend $300 on something a microcontroller and Home Assistant could do.
DIY Solution
Initially, I thought about just buying a spare remote, breaking it open, and wiring up a microcontroller to 'trigger' a button press. I can't remember exactly why I ruled this out. They are relatively cheap - ~$60. However, I have been trying to finish more projects using stuff I already have around house.
I decided to take a look at the motor itself and realized it had terminals for some type of aux port.
Consulting the manual revealed this is indeed an aux port.
Indeed if I temporarily bridged the OSC
and 0V
port the door would operate. The manual however was sparse on specific information about this keyswitch connection. Specifically, it doesn't have information on how long connection needs to be made, the voltage on the pin, and the current that will pass through.
side note: When I originally did this, I think I was looking at an older version of the manual that didn't call this the keyswitch. I'm pretty sure a safe level of current would have to pass through if this was intended to be used with a metal key in a metal key housing.
Hardware
Awhile back I bought a handful of ESP-01 microcontrollers for projects like this. I also bought a NodeMCU which uses the same SoC in a friendlier development kit package. Normally, I use the NodeMCU to get things working and then switch it out for an ESP-01, but I couldn't find anymore of my 5V->3.3V regulators.
I did use a multimeter to measure the voltage. I think it was 5V. I didn't have a way of measuring the peak current that passed through when closing the circuit. I imagine it would have been fine to hook it up directly to a microcontroller pin but I have plenty of 2N2222 transistors lying around. So I decided to be safe and create a simple switching circuit.

The transistor base is connected to a pin on the microcontroller. The collector is connected to the garage door motor OSC terminal. The base is connected to ground. With this circuit, when the pin is driven high, the transistor will turn on, driving OSC to ground and therefore triggering operation of the door.
Detecting what state the door is in
Unfortunately the garage door motor does not have a concept of what state the door is in. Or at least is doesn't 'publish' that information anywhere. Instead each trigger to operate the door just cycles through up, stop, and down. I looked around online and saw many options for sectional doors. A common solution was using some a distance sensor on the roof to detect when the garage door was up.
I had a HC-SR04 ultrasonic sensor so I decided to implement something like that but for a roller door. Instead of mounting it to the roof, I have the sensor pointed at the door a few inches off the ground.
I 3D printed a bracket to hold the sensor and point it at the right spot.


Software
I decided to use ESPHome for programming the microcontroller. Normally I hate things that abstract away so much of the details. However, as my free time has become sparser, I gave in. I was quite pleasantly surprised. Coupled with ChatGPT, I was able to really quickly program the controller. It's super nice have a single yaml file and not needing to deal with arduino or ESP ide installs.
The full configuration is below. It publishes 2 controls and 1 sensor. The sensor uses the ultrasonic sensor to get the distance to the door. The toggle is simply the switch that triggers the garage door operation. Finally the cover is where the actual logic is performed. If the distance is less than a value, the garage door is considered closed. Otherwise it is open. This allows the microcontroller to report the state of the door.
esphome:
name: garagedoor
esp8266:
board: nodemcu
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ""
ota:
- platform: esphome
password: ""
wifi:
ssid: "redacted"
password: "redacted"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Garagedoor Fallback Hotspot"
password: "redacted"
domain: "redacted"
captive_portal:
switch:
- platform: gpio
name: "Garage Door Toggle"
pin: D5
id: "garagedoortoggle"
on_turn_on:
- delay: 1s
- switch.turn_off: "garagedoortoggle"
sensor:
- platform: ultrasonic
trigger_pin: D7
echo_pin: D6
name: "Garage Door Distance"
update_interval: 15s
accuracy_decimals: 1
id: garage_door_distance
cover:
- platform: template
name: "Garage Door"
lambda: |-
if ((isnan(id(garage_door_distance).state)) || id(garage_door_distance).state > 0.060) {
return COVER_OPEN;
} else {
return COVER_CLOSED;
}
open_action:
- switch.turn_on: "garagedoortoggle"
close_action:
- switch.turn_on: "garagedoortoggle"
stop_action:
- switch.turn_on: "garagedoortoggle"
Notifications
I added a simple home assistant automation to send an alert to our phones if the door has been open for longer than 15 minutes.
Conclusion
Things are working as expected with minimal issues. The bracket holding the distance sensor is just held with magnets. If it gets bumped, the measurements can change and the code needs to be adjusted. ESPHome is awesome.