Advertisement

Home/Hardware & Sensor Integration

Build a DIY Smart Lock with ESPHome and Home Assistant: A Step-by-Step Guide

Advanced Home Assistant for DIY Security Enthusiasts · Hardware & Sensor Integration

Advertisement

Why Bother with DIY? Because You Control It.

Aesthetic, moody shot of a commercial smart lock next to a bare, open-source ESP32 development board on a wooden workbench. Cinematic lighting, shallow depth of field. The commercial lock looks sleek but closed off; the ESP32 looks hackable and full of potential.

Let's be real. Commercial smart locks are fine. Until their cloud goes down. Or the company decides your subscription should cost more. You're handing the keys to your literal front door to some server in who-knows-where. Feels wrong, doesn't it? That's the itch this project scratches. With a DIY lock running ESPHome and Home Assistant, everything happens in your house. No middlemen. No monthly fees. Just you, your Wi-Fi, and a glorified door bolt you told exactly what to do. Total control. It's cheaper, too. Way cheaper.

Gather Your Bits: The Hardware Shopping List

Don't panic. This isn't a list of 50 impossible-to-find parts. Here's the core of it. First, the brain: an ESP32. Any dev board will do. Next, the muscle: a 12V electric door strike or magnetic lock. You'll need a relay module to let the ESP32 safely switch that high-power thing on and off. Grab a 12V power supply for the lock, and a 5V USB one for the ESP32. Some wires, maybe a nice project box to hide the mess. That's essentially it. The door strike is the biggest ticket item, and even that's cheap. You're not buying a pre-built "smart" product with a 300% markup. You're buying raw components. It feels different.

The Scary Part: Wiring It All Up

This is where people freeze. Electricity. Relays. It's simpler than it looks, I promise. Your ESP32 can't power the lock directly. It's a delicate flower. The relay is the tough bouncer in the middle. The ESP32 tells the relay (a tiny signal), and the relay slams the circuit closed for the big, beefy lock. Connect the lock's power supply to the relay's "common" and "normally open" terminals. Run two wires from the ESP32's GPIO pins to the relay's control pins. Double-check the power ratings. Maybe triple-check. The goal is an unlocked door, not a magic smoke show. Take a photo of your wiring before you cram it all in a box. You'll thank me later.

Breathing Life In: Flashing ESPHome

Now for the magic. You've got a dumb relay wired to a microcontroller. Time to make it smart. If you use Home Assistant, ESPHome is your best friend. It's a system that lets you describe your hardware in simple YAML code, then it builds and installs the perfect firmware over Wi-Fi. No obscure Arduino libraries. You write a config file that says: "GPIO pin 23 is a switch that controls a relay. Call that switch 'front_door_lock'." You plug the ESP32 into your computer once, flash it via USB, and from then on, everything is wireless. You're not really "coding." You're giving instructions in plain English. Suddenly, that bundle of wires has a name on your network and is waiting for orders.

Bringing It Home: Home Assistant Automation & Your Phone

Here's the payoff. Your ESP32 device pops up in Home Assistant automatically. It's just another switch. But now it's *your* door lock. Create a Lovelace dashboard with a big lock button. Set up an automation to unlock it when you arrive home. Maybe lock it every night at 11 PM. You can add keypads, fingerprint sensors, or NFC tags later—all controlled by this same system. The lock is no longer a single function gadget. It's a node in your home's intelligence. You can see its status from anywhere, get notifications if it's left unlocked, and control it with your voice. This is where the DIY path utterly destroys commercial options. The integration is profound, because you built it.

A Note on Security (Because It Matters)

We built this to be *more* secure, right? So let's not be dumb. Keep your Home Assistant instance updated. Use strong passwords. Enable 2FA. Consider putting your IoT devices (like this ESP32) on a separate Wi-Fi network VLAN. The lock's physical security still depends on your door and strike plate. The DIY part replaces the electronic guts, not the solid metal bits. This setup is arguably more secure than a cloud lock because the attack surface is your local network, not the entire internet. But that means your network's security is now part of your door's security. Act accordingly.