Introduction: Siri HomeKit Controlled ESP8266 Lock

I built a custom HomeKit / Siri controlled election lock recently. It need ESP8266/NodeMCU, Raspberry PI and a Electric Lock 12V DC. You can also replace Raspberry PI with exists PC or cheaper option -- Orange PI.

I wrote a homebridge plugin homebridge-esplock for better working with ESP8266. Using homebridge-esplock plugin and homebridge, you can say:

  • Siri, unlock the back door.
  • Siri, open the garage door.

Step 1: Materials

  • ESPea - Mini ESP8266 Dev Kit.
  • Relay Shield for ESPea - an add-on board that allows your ESPea to control higher voltage and current loads through a relays.
  • Lock-style Solenoid - 12VDC - Buy from Tindie
  • 12V power adapter - You can easy find a proper power adapter from old WiFi router.
  • iPhone - For HomeKit control

Step 2: ​Install HomeBridge for HomeKit

Homebridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It supports Plugins, which are community-contributed modules that provide a basic bridge from HomeKit to various 3rd-party APIs provided by manufacturers of "smart home" devices.

For installation Homebridge, please check the wiki

I used my macbook to run the homebridge server. Homebridge is published through NPM and should be installed "globally" by typing:

sudo npm install -g --unsafe-perm homebridge

Note: If you're running on Linux, you'll need to make sure you have the libavahi-compat-libdnssd-dev package installed. If you're running on a Raspberry Pi, you should have a look at the Wiki. I aslo tried to run homebridge on a cheap Orange PI zero($7) and it works fine.

Homebridge support a bunch of plugins. I wrote a plugin homebridge-esplock that support esp8266 better (modified from homebridge-httplock. Thanks for the plugin).

Install plugin homebridge-esplock by typing:

sudo npm install -g homebridge-esplock

Step 3: Wire Together

The Relay Shield is a stackable shield for ESPea. It wires relay pin to ESPea D1 pin default.

  • Stack the Relay Shield to ESPea board. Let the micro usb cable to outside so you can programing it easier
  • Wire DC 12V+ to lock's red line.
  • Wire lock's black line to the middle port of relay
  • Wire DC 12V- to relay's NC port

Note: The ESPea need 5V DC to drive the relay. So you need keep plugging the micro usb cable.

Step 4: Arduino Setup and Upload Sketch

Program ESPea with Arduino IDE.

  • Get the sketch from GitHub
  • Change the ssid, password in the sketch to yours
  • Upload to ESPea

Reset ESPea and see the serial monitor in Arduino IDE. You will find out the IP address for it. Let's the IP is Write config file for homebridge

"bridge": { "name": "Homebridge", "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-154" },

"description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.",

"accessories": [ { "accessory": "EspLock", "name": "Front Door", "url": "", "lock-id": "1", "username": "test", "password": "test" } ] }

Now let's run homebridge with command line


Step 5: Controlling the Lock With Siri

Let's try to control the lock by HomeKit

  • Open and add new ccessory
  • Test lock or unlock
  • Try with Siri to unlock the door

Note: The lock will change back to locked status after 5 seconds. Because the lock can't keep unlock status long time (Must < 10s).

IoT Builders Contest

Participated in the
IoT Builders Contest