Garage Door Opener
A bare-bones ESP32 based HomeKit enabled garage door opener using HomeSpan.
Hardware
To avoid any modification to the garage door opener itself, I designed the board to use its own position sensor and emulate a wall switch to trigger the garage door movement. Some commercial products emulate a wireless remote and indeed the ESP32 does have some special function hardware for generating pulse code signals, however I decided to skip the complexity for this first revision as the holiday season presented some serious schedule pressure for getting this finished. Likewise, for the door position sensor some products use a tilt sensor with the assumption the board would be glued to the moving door itself. I again opted for the simpler solution of a microswitch mounted on one of the door's guide rails to avoid the complexity of dealing with battery power and wireless control.
To actuate the door, a wall switch normally would short a pair of lines connected to terminals on the back of the garage door opener. I measured these terminals with a voltmeter and found the high side was pulled up to 24V nominal, above some floating ground potential. Also of note is that the threshold voltage for triggering was quite low, less than 0.1V difference. The ideal part to use in this case would be a small relay, but I didn't have any on hand. As an alternative, I ended up using an optoisolator with an NPN transistor in a Darlington configuration to achieve the isolation and current capacity needed to drive the opener's trigger line low.
One unexpected issue that came up after the board arrived was that the NPN BJT was not fully turning on before the line voltage collapsed, leaving the line stuck at a ~0.7V base emitter diode voltage, which was just a bit above the threshold voltage for triggering the opener. I bodged in a 0.1 µF capacitor between the high/low side of the screw terminal to fix this. The extra capacitance ensures the BJT has just enough time to fully turn on, driving the line completely low and triggering the opener.
Firmware
The firmware relies on the excellent HomeSpan project to implement HomeKit support. It was very straightforward to implement a GarageDoorOpener service and hook it up to the appropriate inputs/outputs. With some fine tuning of switch debouncing, everything was installed and ready by Christmas.