Contents

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.

Requirements

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)
  • LEDs
  • 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.

Mechanical Installation

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:

/posts/smart_mechanical_garage_lock/lock4-min.jpg

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:

ESP8266 D1 mini Configuration Description
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:

Command Description
SetOption80 1 Enable shutter support
Shutterrelay1 1 Define RELAY1 for ON/OFF, PWM1 for the servo
Shuttermode 5 Servo shutter mode
PWMfrequency 200 Frequency for all servos
SetOption15 0 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.

Command Description
ShutterPwmRange1 264, 420 open/close values for the servo (switch values to switch open and close)
ShutterOpenDuration1 0.5 Opening time in seconds (doesn’t really matter)
ShutterCloseDuration1 0.5 Closing time in seconds
ShutterMotorDelay1 0.2 Prevent abrupt start
Restart 1 Restart to apply changes

Now you’re able to control the lock using the commands below. Tweak the PWM range and timings if necessary.

Command Description
ShutterOpen1 Open the lock
ShutterClose1 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.

Navigate to 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:

/posts/smart_mechanical_garage_lock/lock5-min.png

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:

ESP8266 D1 mini Configuration Description
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:

Command Description
i2cscan Scan for the display on the I2C bus
DisplayAddress 0x3c Setup the display. Replace 0x3c with the address from the I2C bus scan
DisplayModel 2 Set the display type to SSD1306
DisplayDimmer 100 Set the display to full brightness (can only be 0 for off or 100 for on)
DisplayMode 0 Set the display mode to custom text
SetOption73 1 Detach the buttons from the relays
Rule1 ON button1#state DO ShutterToggle1 ENDON Setup Rule 1 to toggle the lock on a button press
Rule1 1 Enable Rule 1
Rule2 ON shutter1#position > 50 DO Displaytext [c1l2f0s2] UNLOCKED ENDON ON shutter1#position < 51 DO Displaytext [c1l2f0s2] LOCKED ENDON Setup Rule 2 to display the lock state when the lock state changes (two leading spaces before text LOCKED to overwrite the UN with spaces)
Rule2 1 Enable Rule 2
Rule3 ON Time#Minute|1 DO Displaytext [s1l1c1T] [s1l1c10t] ENDON Setup Rule 3 to update the current date and time every minute
Rule3 1 Enable Rule 3

Images

Controller PCB

/posts/smart_mechanical_garage_lock/lock2-min.jpg

Schematic for the controller

/posts/smart_mechanical_garage_lock/lock3-min.png

References

  1. https://tasmota.github.io/docs/Blinds-and-Shutters/
  2. https://www.home-assistant.io/integrations/tasmota/