Siri HomeKit Controlled ESP8266 Lock

12,837

72

7

Published

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 192.168.1.5. 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": "http://192.168.1.5/", "lock-id": "1", "username": "test", "password": "test" } ] }

Now let's run homebridge with command line

homebridge

Step 5: Controlling the Lock With Siri

Let's try to control the lock by HomeKit

  • Open Home.app 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).

Share

Recommendations

  • Water Contest

    Water Contest
  • Oil Contest

    Oil Contest
  • Creative Misuse Contest

    Creative Misuse Contest

7 Discussions

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

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

0
user
except

Question 5 months 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 ?

0
user
except

Question 5 months ago

Hello.
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.

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

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

1 reply

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