Unlocking the front door using the mobile phone and Home Assistant

Link to the original blog post with a nice text/pictures layout.

The problem:

  • kids keep forgetting to carry the key to unlock the front door. They never forget to carry their phones though.

The solution:

  • unlocking the front door using a mobile phone

HW parts:


The process:

  1. I installed a wall box near the front door, under a nearby electrical socket (see below)
  2. When the company installed the front door, I asked them to install a UTP cable from the door lock mechanism to the socket.
  3. Bought the materials above (Aliexpress for the boards, Conrad for the power suppy).
  4. Connected the mains to the breaker (for emergency switch-off)
  5. Connected the cables from the breaker to the 24V power supply
  6. Connected the cables from the power supply to the ESP32 board, door solenoid relay and ESP32’s relay. Luckily, I didn’t need to install 5V power supply for the ESP board, because it also works with 24V.

Here’s the doodle of the connecting scheme:

doodle of the electrical scheme

Here’s the original connecting scheme from Innotherm (door manufacturer), in Slovenian: It was useful because it reveals which power supply is appropriate (Meanwell MW HDR 30-24).

the electrical scheme for wiring the door unlocking mechanism

7. Fitted everything in the wall box. It was too shallow! I couldn’t hide all the junk with the flat cover that came with a box.

    Before fitting:

    circuit breaker, power suppy and esp32 board hanging out of the wall box

    Everything nicely fit in a box:

    circuit breaker, power suppy and esp32 board nicely ft in the the wall box

    8. I designed and 3D printed a new cover in TinkerCad:

      3d model of the wall box cover

      10. After a 3rd try (of 3D design and printing), all measures were finally correct and I could cover the box (Mastodon post):

      wall box cover mounted

      11. Flashed ESP32 board with ESPHome*, added it to Home Assistant.

      (*Actually it wasn’t that simple. The board doesn’t have a data USB connector. I had to buy USB2TTL adapter. I was bitching about it here.)

      esp32 board with usb2ttl adapter connected

      Nevertheless, after the firmware update, I edited .yaml for the board so it exposes:

      Main entity:

      • Switch (for controlling relay), connected to GPIO16

      Misc. entities:

      • LED light (connected to GPIO 23, to signal when the door is opened)
      • Wifi sensor (for checking the power of Wifi signal, because the esp board is located in a wall box)
      • Uptime (to see the time since the last esp board reset)
      • Restart switch (to remotely restart the board if needed – but until now it wasn’t needed)

      .yaml code for ESPHome (gathered from various websites, mainly from ESPHome):

      12. I’ve put an NFC sticker on the door.

      13. Wrote 2 simple automations that open a relay when the phone touches the NFC sticker and closes it after 1 second:

      screenshot of the door unlock automation

      2nd automation switches the relay off after 1 second (also blinks the red status led on the ESP board):

      screenshot of the door lock automation

      14. Added Aqara Door sensor to the door and connected it my existing Zigbee network using Zigbee2MQTT. It’s for logging when the door is open and for turning on the red status LED on the ESP32 board when the door is opened.

      aqara door sensor mounted at the edge of the door

      15. Added a new control dashboard in Home Assistant for tracking what’s going on with the door:

      dashboard in home assistant with various door statuses


      After 6 months, it works great. Kids are satisfied and me too, because this is one of the first usable HomeAssistant projects that involve some electronics and physical devices. It works in 99% of cases.

      There are some issues with it though:

      • The ESP32 board sometimes reboots after unlocking. It seems that the door solenoid relay draws too much current and the voltage from the power supply drops momentarily. Probably I need to add a capacitor to the board power input to smooth the voltage. This is not a big issue, because the board starts working normally after 3 or 4 seconds after the reboot.
      • Once or twice it happened the esp board relay got stuck in an OFF state. I had to hit it gently with a screwdriver to unstuck it. After that, I reduced the time the door solenoid is opened from 2 to 1 sec. Not sure if it will help. Maybe it’s just a bad relay.
      • Several times the wifi was down and the board couldn’t communicate with the Home Assistant. It looks like my telco provider’s router is not the best one and it freezes sometimes. Probably I need to buy a better wifi router.


      I have several ideas on how to upgrade the unlocking mechanism:

      • unlocking with a fingerprint
      • unlocking with facial recognition


      The links to the products are not affiliate links and I don’t receive any compensation for linking.

      The code and the ideas are mostly from HomeAssistant and ESPHome community forums.




      15 responses to “Unlocking the front door using the mobile phone and Home Assistant”

      1. jaKa Močnik Avatar

        @tomi lol, v kakšnih enotah je un končni navor? sili funta na inč? 😀

        1. jaKa Močnik Avatar

          @tomi in kako avtoriziraš telefon?

          1. Miha Markič Avatar

            @jkmcnk @tomi ^^^ socialni inženiring v praksi 🤪

            1. Tomi the Slav and 1024 others Avatar

              @mihamarkic @jkmcnk @tomi

              To je v resnici reverse social inženiring, limance za infosec-e. Če kdo uspe odkleniti, je sprejet in posvojen v našo družino. Pa v kleti bo nekaj časa. 🤪

              1. jaKa Močnik Avatar

                @po3mah ti sofisticirani prijemi se sam v locksports uporabljajo, resničnost je pajser in šraufenciger. @mihamarkic @tomi

            2. jaKa Močnik Avatar

              @mihamarkic wat, there is no security through obscurity. 😜 @tomi

          1. jaKa Močnik Avatar

            @po3mah tam nekje na mašineriji piše terminal torque. @tomi

            1. Tomi the Slav and 1024 others Avatar

              @jkmcnk @tomi O, pa res, sploh nisem opazil. Bom uveljavljal reklamacijo, ker herezije pa ne bom podpiral.

              1. jaKa Močnik Avatar

                @po3mah men se zdi to krasno, še bolje bi bilo meriti navor v sili bika pitanca na seženj. @tomi

              2. Tomi the Slav and 1024 others Avatar

                @jkmcnk @tomi Ti se kar hecaj, nekoč v zgodovini se je nekdo tudi hecal in so ga resno vzeli in zapisali. Sedaj pa imamo enote, kot so "large boulder in the size of a small boulder" in podobne. 🙂

      2. Tomi the Slav and 1024 others Avatar

        @linjari @tomi Thanks! I have no idea how to calculate the correct values for the cap, will try to find out how…
        The power supply is rated as 24V 1.5A max.

        1. Tomi the Slav and 1024 others Avatar

          @linjari @tomi Great, thanks!
          Will try to put one 1N4001 in a series with a relay.

      Leave a Reply

      Your email address will not be published. Required fields are marked *