Control Mechanical Garage Door Lock with Tasmota and Home Assistant
Not everyone has the option of installing an electric garage door opener, but in some situations it can still be useful to be able to unlock the door with a wireless remote or your smartphone. Most garage doors provide the option to unlock the door from the inside without a key using a small lever. By attaching a small servo motor to it, the lock can be automatized and controlled remotely.
This guide shows how such a smart mechanical garage door lock can simply be made from cheap off the shelf components (sub $20) and a bit of computer knowledge. It describes the steps to build the hardware, set up the microcontroller and automate it using Home Assistant.
You need a few components for smartifying your mechanical garage door lock. There are several different options for those, following are just examples:
- Wemos D1 Mini ESP8266 Board (ESP32 etc. should also work)
- Servo SG90
- Relay (you can use a breakout board for SRD-05VDC-SL-C for example or alternatively control the servo power using a transistor)
- USB charger + cable for powering the ESP8266 Board (10W should be enough to power the ESP8266 and servo)
- Cable for connecting the servo on the door to the controller on the wall (3 wires, 3+ meters)
You need to connect the Relay to D3 on the D1 mini, the Servo to D4, the LED to D5 and the switch to D6. See below for a schematic.
First you need to attach the servo to garage door locking lever. You can build a mounting bracket using wood or 3d print one. I just used epoxy glue to attach it.
The connection between the servo head and locking lever can be 3d printed or a strong wire which is still a bit flexible can be used to account for the radial movement of the servo.
Attach a long cable to the servo. The cable can hang down the side of the door where it is connected to the controller.
The mounted servo should look like this:
Configuring the D1 mini
One the software side, you need to flash a version of Tasmota with shutter support to the D1 mini board. Shutters are supported by all newer versions of
tasmota.bin. You will find various guides on flashing Tasmota on the internet.
After flashing Tasmota to your D1 mini, open the web interface, go to
Settings > Configure Device and set the device type to
Generic and choose following pin configurations:
|GPIO 0||D3||Relay (1)||Servo Enable|
|GPIO 2||D4||PWM (1)||Servo Control|
|GPIO 14||D5||Relay (2)||Direction Indicator|
|GPIO 12||D6||Switch (1)||Control Switch|
Then, you can setup the shutter control using the Tasmota Web Console by typing following commands:
||Enable shutter support|
||Define RELAY1 for ON/OFF, PWM1 for the servo|
||Servo shutter mode|
||Frequency for all servos|
||Enable basic PWM control|
The next step is to set the range of the servo. You can find the timings for 0° and 180° in the servo datasheet. As you probably do not need the full range of the servo, you can try out different opening and closing timings between those.
You can calculate the values for Tasmota using this formula:
timing_us * freq/1000, for example
1320µs * (200Hz / 1000) = 1320 * 0,2 = 264.
||open/close values for the servo (switch values to switch open and close)|
||Opening time in seconds (doesn’t really matter)|
||Closing time in seconds|
||Prevent abrupt start|
||Restart to apply changes|
Now you’re able to control the lock using the commands below. Tweak the PWM range and timings if necessary.
||Open the lock|
||Close the lock|
Lastly, you can configure the switch input. This can for example be used to detect whether the garage door is open using a reed switch.
You may want to enable
SetOption114 1 to detach the switch from the relay and rather send a MQTT message to Home Assistant when the state changes.
Automations in Home Assistant
In Home Assistant, you first need to add the Tasmota extension if not already done. You also need to set up your MQTT broker on the Tasmota web interface. Home Assistant should then automatically detect the controller.
Settings > Automations & Scenes and create a new Automation there. There you can for example configure a Zigbee remote or a companion app action as the trigger.
For the action choose
Close ... cover 1 or
Open ... cover 1 (where
... is the device name configured in the Tasmota web interface).
If you want to define a toggle action, you can add a condition like this:
Adding a display
If you want the smart lock to show the current status of the lock and the current date and time, you can add a display to it. Additonally, a button to manually control the lock can be added too.
Required parts: SSD1306 OLED (128x32 pixel), push button
Configure Tasmota and connect the parts according to the table below:
|GPIO 16||D0||Button (1)||Button to open/close the lock|
|GPIO 4||D2||I2C SDA||SSD1306 display SDA pin|
|GPIO 5||D1||I2C SCL||SSD1306 display SCL pin|
Next, you need to setup the display, button and rules for the automation. For this you need to run following commands in the Tasmota Web Console:
||Scan for the display on the I2C bus|
||Setup the display. Replace
||Set the display type to SSD1306|
||Set the display to full brightness (can only be 0 for off or 100 for on)|
||Set the display mode to custom text|
||Detach the buttons from the relays|
||Setup Rule 1 to toggle the lock on a button press|
||Enable Rule 1|
||Setup Rule 2 to display the lock state when the lock state changes (two leading spaces before text
||Enable Rule 2|
||Setup Rule 3 to update the current date and time every minute|
||Enable Rule 3|
Schematic for the controller