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

2 People Made This Project!


  • Beauty Tips Contest

    Beauty Tips Contest
  • Planter Challenge

    Planter Challenge
  • Growing Beyond Earth Maker Contest

    Growing Beyond Earth Maker Contest

10 Discussions


Question 10 months ago on Step 5

When I open the home App and add new accessory it does not shows up any control options to turn on the event. It just shows up the icon in the image and when I click it it does nothing. Could anyone help me out, thanks for the tutorial BTW

1 answer

Answer 10 months ago

Found the problem it was a missing ‘s’ in the word ‘accessories’ heheh


2 years ago

How many relays can raspberry control?
Can wifi control be added to control wifi switches? Or 433mhz

2 replies

Reply 2 years ago

ESP8266 control relays. You can add more devices in config.json on raspberry pi.


Reply 11 months ago

Tell me, you have a plugin for raspberri pi and a code for wemos d1 mini.
to turn the relay on and off.
I want to run a light bulb, but your example does not suit me very much.


Question 1 year ago on Step 5

Hi, very good tutorial! Awesome! But is it possible to keep the status in on or off? Just an example to switch on or off a light. Thanks


1 year ago

Got it running !! Nice tutorial ! Easy to follow ! Please make a tutorial to turn on and off a relay with homekit ! and a physical push button also to turn the relay on of off with a single click.

Thanks in advance


Question 1 year ago

I just see that when press icon (3dtouch ) i getting information " battery low " and it's probably purpose for exlamanation mark. But when open details i see battery level 100%. So what is going on ?


Question 1 year ago

Good job.
I have few questions - in my case after run homebridge i can control lock from homekit , but on the lock icon is exclamanation mark and i dont know why - on your pictures ur icon is all right.
I need only one trigger activation. But in my case it doing twice.


1 year ago

how can i deactivate to trigger the gpis pin when it is switching back to locked again?