Skip to content
My Account

HomeKit

ESP8266 HomeKit Door Lock

A 12 V electric lock controlled from the Home app with an ESP8266 and a relay, with a manual button and a 5 second automatic relock. A breadboard build made to test the firmware.

  • ESP8266
  • HomeKit
  • 3 min read
No ratings yet, be the first.

This project turns a 12 V electric lock into an Apple HomeKit accessory. An ESP8266 switches the lock through a relay, and you open and close it from the Home app or with Siri, with a button on the device as a manual backup. The lock relocks by itself after 5 seconds.

It is a breadboard build that was made to test the firmware and to see whether it can be used in practice, so treat it as a working prototype and not as a finished door lock.

What it does

FeatureDetails
HomeKit lockThe lock shows up in the Home app, with open and close control
Automatic relockThe lock closes again after 5 seconds
Manual controlOne push button opens and closes the lock
LEDBlinks for HomeKit Identify and shows whether the lock is open or closed
UpdatesOver the air, through Life Cycle Manager 2
No cloudControl stays on your own network, like the other HomeKit accessories on this site

Hardware

ComponentNotes
ESP8266 moduleAn Ai-Thinker ESP8266 module of the ESP-12 type. See the ESP8266 pinout
1-channel relay moduleA Keyes SRD-05VDC-SL-C module, with NC, C and NO screw terminals
12 V electric lockCompact and water resistant, electronically controlled, made for cabinets and doors, easy to install
3 push buttonsOne to open and close the lock, one for boot and one for enable, both used for programming
LEDIdentification and lock status
USB-serial (FTDI) adapterFor the first flash, set to 3.3 V logic
Resistors and capacitorsPull-ups and decoupling, as shown in the diagram

The relay module is marked for 10 A at 250 V AC and 30 V DC. The lock only needs 12 V DC, which is well inside that. The lock’s 12 V supply is switched through the relay contacts.

Wiring

The Fritzing diagram at the top of this page shows the whole build on a breadboard. Reading it against the module’s pinout gives this pin assignment:

FunctionESP8266 pin
Relay signalGPIO12
Open and close buttonGPIO4
Boot button (programming)GPIO0
LEDGPIO2
Serial to the FTDI adapterTXD and RXD

These pins are read from the Fritzing diagram and are not listed in the repository text, so check them against the diagram before you build. The enable line has a pull-up resistor, and a button is wired to it for programming. Use an FTDI adapter set to 3.3 V, because a 5 V adapter can damage the module.

Buttons and LED

PartWhat it does
Left buttonOpens and closes the lock
Boot buttonPuts the module in programming mode
Enable buttonUsed together with the boot button when programming
LEDBlinks when HomeKit sends an Identify request, and shows whether the lock is open or closed

Flash and install

The installation is the same as for the other ESP8266 HomeKit accessories on this site. The firmware runs on ESP-Open-RTOS with Life Cycle Manager 2, which sets up the WiFi and installs updates over the air. The full steps, from installing esptool to flashing, joining the LCM- WiFi network and pairing, are in ESP8266 HomeKit Blinds.

For this accessory, use these values in the Life Cycle Manager 2 portal:

FieldValue
OTA repositoryAchimPieters/ESP8266-HomeKit-Lock
OTA binary filemain.bin

When the installation is done, scan the QR code the device generates in the Home app to add it.

Firmware releases

VersionDateChanges
0.0.228 August 2020Minor bug fixes and OTA update added
0.0.124 May 2019First release

Each release has a main.bin and a signature file, main.bin.sig.

Good to know

  • This is a test setup. Check how the lock behaves when the power fails before you rely on it for a real door or cabinet.
  • The HomeKit Accessory Protocol specification the firmware follows is the non-commercial version, for accessories you build yourself and do not distribute or sell.
  • The firmware is distributed as binaries in the releases. The repository has the wiring diagram and licence (MIT), but no source code.

Everything is in the ESP8266-HomeKit-Lock repository on GitHub.

Advertisement
All HomeKit

More HomeKit

Keep building.

Switches, sensors, plugs and blinds: more accessories that you build yourself and add to the Home app.

All HomeKit