by

Tags:


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:

SW:

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

Conclusion

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.

TODO

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

  • unlocking with a fingerprint
  • unlocking with facial recognition

Disclaimer

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.

Thread on Mastodon

https://mastodon.social/@po3mah/111306836068315890

Update 1: the relay broke

Sometime in June 24 (after hald a year of installation), a relay broke. I hear the relay click sound when I activate the relay, but the door stays closed. I measured the resistance of the relay and it’s always disconnected. The door relay is fine, I connected it directly and it opened.

Probably I have to add a capacitor and/or rectifier diode to a circuit to prevent voltage swings and reverse voltage/current. When the solenoid closes probably it induces a current…

Update 2: fixing the broken relay

… in progress … (I’m not an electronics professional – if there are mistakes, please correct me)

What kind of circuit I need to prevent the voltage drop when solenoid opens and reverse current when closes?

Probably this is the circuit I need (I have a relay instead of transistor):

Source: https://electronics.stackexchange.com/questions/167484/electrolytic-capacitor-in-solenoid-circuit

So how big capacitor should I add?

i=CdU/dt => C=Idt/dU =>
I=250mA (ESP max current draw)
dt=2 sec. (time of relay open)
dU=24V (initial voltage of transformer) – 10V (allowed voltage drop, not sure, ESP works from 7V up)
C=0.25A * 2 sec./ (24V-10V) =>
C= 0.035 F = 35 000 uF = 35 mF

This sounds … pretty big, when I googled this big capacitors I became sceptical if the calculation is correct. This big capacitor costs ~15€… Probably this is not correct. Maybe I misunderstood which t should be used in the formula (probably not the duration of solenoid being opened, but the time of change from open-close and vice versa). If I speculate the time of the solenoid switch is 0.1s then C=1041uF which sounds more realistic. But I’m still not sure if I’m on the right path.

After some googling I found out I have to use another formula. It’s an energy management problem, not (directly) a relation between C, I, U and t.

The rabbit hole of solenoids is deep (1, 2, 3).

So the formula for energy stored in solenoid is:

E=1/2 * C * U2

… but I don’t know how much energy is stored by the solenoid.

(…to be continued)

….

Another thing I have to put in the circuit is a flyback diode / rectifier diode like 1N400x to prevent reverse voltage.

(… to be continued …)



Comments

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

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

  1. 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.
      https://en.m.wikipedia.org/wiki/1N400x_rectifier_diode

  2. 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. 🤪

Leave a Reply

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