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:

ESP8266D1 miniConfigurationDescription
GPIO 0D3Relay (1)Servo Enable
GPIO 2D4PWM (1)Servo Control
GPIO 14D5Relay (2)Direction Indicator
GPIO 12D6Switch (1)Control Switch

Then, you can setup the shutter control using the Tasmota Web Console by typing following commands:

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

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

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

CommandDescription
ShutterOpen1Open the lock
ShutterClose1Close 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:

ESP8266D1 miniConfigurationDescription
GPIO 16D0Button (1)Button to open/close the lock
GPIO 4D2I2C SDASSD1306 display SDA pin
GPIO 5D1I2C SCLSSD1306 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:

CommandDescription
i2cscanScan for the display on the I2C bus
DisplayAddress 0x3cSetup the display. Replace 0x3c with the address from the I2C bus scan
DisplayModel 2Set the display type to SSD1306
DisplayDimmer 100Set the display to full brightness (can only be 0 for off or 100 for on)
DisplayMode 0Set the display mode to custom text
SetOption73 1Detach the buttons from the relays
Rule1 ON button1#state DO ShutterToggle1 ENDONSetup Rule 1 to toggle the lock on a button press
Rule1 1Enable Rule 1
Rule2 ON shutter1#position > 50 DO Displaytext [c1l2f0s2] UNLOCKED ENDON ON shutter1#position < 51 DO Displaytext [c1l2f0s2] LOCKED ENDONSetup 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 1Enable Rule 2
Rule3 ON Time#Minute|1 DO Displaytext [s1l1c1T] [s1l1c10t] ENDONSetup Rule 3 to update the current date and time every minute
Rule3 1Enable 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/