This is my 2nd version of a smart lock which is using a stepper motor which allows the user to turn the key manually. This is very useful if the lock supports anti-lockout which will enable someone from the outside still use his key manually.
It’s designed to be used for European Cylinders and it’s possible to fit it without the need of screws.
Checkout my video demonstration:
To control the lock from the inside you can add a button on the ESP32, but on the outside you need something more secure. These are some of my ideas:
- Using buttons on Home Assistant interface.
- If you have the Home Assistant app on your phone, you can stick NFC tags and program them to unlock the door.
- Use an RFID controller like the RDM6300, RC522 and PN532. You can have your personal NFC tags that you can scan on the device. Be warned that the Tag UID can be replicated and the phones emit a random UID.
- Add a Fingerprint sensor like the R503. Check this on how I did it.
For locking you can be more creative because security is not a concern.
- Using a button connected to the ESP32.
- Automatically lock every time the door closes with a magnetic sensor.
- With a Bluetooth LE toothbrush using the ESPHome integration.
- Zigbee/ZWave smart buttons.
- If you are using Asterisk, you can create an extension that calls the Home Assistant API to unlock.
- Using a smart speaker. Be careful with these because they allow you to unlock, but you need to provide a pin. You are heavily depending on an online service that can be hacked, so I wouldn’t recommend it.
The components that I used are these:
- Nema 23 Stepper Motor
- A4988 Stepper Motor Driver
- 3D printed model available here
And this is how everything is connected:
I am using ESPHome to control the motor because it can easily integrate with Home Assistant and supports all features I need out of the box.
The code is designed so when unlocked, the latch will open for 2 seconds and then go to neutral position. After that it will set the neutral position to 50 in case the lost of steps on the motor. This is considered Unlocked.
When it’s locked, it will turn all the way to the desired position and send the locked state on Home Assistant.
Here is the configuration on ESPHome:
esphome: name: smartlock platform: ESP32 board: nodemcu-32s wifi: ssid: <yourssid> password: <yourpassword> # Enable logging logger: # Enable OTA updates ota: # Enable Home Assistant API api: globals: - id: is_locked type: bool restore_value: yes initial_value: 'true' switch: - platform: template name: "Lock Switch" id: lock_switch lambda: "return id(is_locked);" turn_on_action: - stepper.set_target: id: my_stepper target: 2300 - globals.set: id: is_locked value: 'true' turn_off_action: - stepper.set_target: id: my_stepper target: -500 - wait_until: # Wait until endstop reached lambda: 'return (id(my_stepper).current_position == id(my_stepper).target_position);' - globals.set: id: is_locked value: 'false' - delay: 2s # Leave latch open - stepper.report_position: id: my_stepper position: -370 - stepper.set_target: id: my_stepper target: 0 stepper: - platform: a4988 id: my_stepper step_pin: GPIO18 dir_pin: GPIO05 max_speed: 600 steps/s sleep_pin: GPIO19
This lock doesn’t have a feedback if the motor actually reached its destination so I created a new switch that forces to unlock the door:
switch: - platform: template name: "Reset Position" id: reset_position lambda: "return false;" turn_on_action: - stepper.report_position: id: my_stepper position: 750
I’ve been using this smart lock for several days now and the only problem I faced is that sometimes the motor didn’t move enough, which resulted the latch not opening all the way. This was not a problem getting inside because of the reset_position button I created. [update after 2 months] The problem was with the motor driver which I replaced and now it works perfectly without the need of reset_position.
As I mentioned this is my 2nd version of the Smart Lock. If you want, you can check the 1st version here which is using a worm motor that locks the key in place.
Hope you like it!