I recently started a project based on this blog write up: Making a Dumb Lock Smart with DIY Hardware and ESPHome
I’m using the same servo, lock, and 3d printed parts as a base. The blog post uses an ESP8266 board, I’ve opted for an ESP32 board for additional bluetooth functionality. I’ve modified the code for the upgraded board and implemented the newer ESPhome lock component.
Everything seems to work initially, occasionally the servo sticks and is non responsive for random periods of time. Waiting and toggling lock unlock fixes the issue sometimes. Here’s the code:
esphome:
name: rear-lock
esp32:
# default board type
board: esp32dev
framework:
type: arduino
output:
- platform: ledc
id: lock_servo
pin: GPIO27
frequency: 50Hz
servo:
- id: servo1
min_level: "2%"
max_level: "12.6%"
output: lock_servo
lock:
- platform: output
# id is for firmware call reference
id: rear_lock
# name is for esphome reference
name: "rear_lock"
output: lock_servo
# on_lock action to take when lock is locked component call: -lock.lock: rear_lock
on_lock:
- servo.write:
id: servo1
level: -0.9
- logger.log: "Door Locked!"
# on_unlock action to take on component call: -lock.unlock: rear_lock
on_unlock:
- servo.write:
id: servo1
level: 0.3
- logger.log: "Door Unlocked!"
binary_sensor:
- platform: gpio
# id used as reference / alias
id: lock_button
# input pin
pin:
number: GPIO5
mode: INPUT_PULLUP
on_press:
# lock usage
- lock.lock: rear_lock
on_release:
#lock usage
- lock.unlock: rear_lock
# Enable logging
logger:
# added in project
debug:
# Enable Home Assistant API
api:
encryption:
key: ""
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
observations:
-Log doesn’t show loss of power due to servo load
-Log shows binary_sensor input signal and home assistant lock and unlock are being received by board
-Log shows PWM signal being sent to servo
-When servo sticks toggling binary_sensor pin on/off usually, but not always fixes problem
-Board reboot fixes problem consistently
any suggestions welcome