Electronics
Door Lock with an ESP8266 and Homebridge
An ESP8266 that opens a door lock through a relay and a web request, shown as a lock in the Home app by a Homebridge plugin.
- ESP8266
- Homebridge
- Archived
- Safety notes
Archived project
The GitHub repository for this project is archived: it is read-only and no longer updated. What follows describes the project as it was, so check for a newer alternative before you build it.
A door lock that you open from the Home app. An ESP8266 switches a relay that powers the lock, and a Homebridge plugin shows it as a lock in HomeKit. The lock closes again by itself after a few seconds.
Homebridge is a program that runs on a computer such as a Raspberry Pi, and makes devices that do not support HomeKit show up in the Apple Home app. This project dates from the Homebridge years, before the native HomeKit firmware of this site. For how the site builds HomeKit devices today, see HomeKit or Matter for your ESP32.

The ESP8266 side
The ESP8266 runs a small web server. The relay is on pin 13.
| Request | What it does |
|---|---|
GET / | Answers {"state":"locked","statusCode":200} or "unlocked", from the state of the relay |
POST / with state=locked | Switches the relay off |
POST / with another state | Switches the relay on, and off again after the timeout of 5000 ms |
Every change is answered with {"battery":100,"statusCode":200}.
The Homebridge side
The plugin registers an accessory called HTTPLock that has a lock mechanism, with its current and target state, and a battery service with the battery level and the charging state. It reads its settings from the configuration of Homebridge: the name, the address, a lock ID, a user name and a password.
Security
This is a door lock. Anything on your network that can send a request to the ESP8266 can open it, so put it on a network you trust, and do not use it as the only lock on a door that protects something valuable.
Good to know
- The sketch is version 2.2.0.
- The repository is under the MIT licence.
- Apple, HomeKit and Homebridge are trademarks of their owners. This project is not made or approved by them.
The project is in the Apple-Homebridge-Door-Lock repository on GitHub.
More projects
Keep building.
Electronics, 3D printing and CNC builds, documented from the first idea to the last screw.
All projects

