Skip to content

Instantly share code, notes, and snippets.

@tjhorner
Created Sep 4, 2021
Embed
What would you like to do?
esphome:
name: smartlock
platform: ESP8266
board: d1_mini
output:
- platform: esp8266_pwm
id: pwm_output
pin: D1
frequency: 50Hz
servo:
- id: lock_servo
min_level: "2%"
max_level: "12.6%"
output: pwm_output
switch:
- platform: template
id: lock_switch
name: "Front Door Lock"
icon: "mdi:lock"
optimistic: true
restore_state: true
turn_on_action:
- servo.write:
id: lock_servo
level: -0.9
turn_off_action:
- servo.write:
id: lock_servo
level: 0.3
binary_sensor:
- platform: gpio
id: lock_button
on_click:
- min_length: 50ms
max_length: 1s
then:
- switch.toggle: lock_switch
- min_length: 1s
max_length: 5s
then:
- switch.turn_off: lock_switch
- delay: 10s
- switch.turn_on: lock_switch
pin:
number: D5
inverted: true
mode: INPUT_PULLUP
- platform: gpio
id: hall_sensor
name: "Front Door Position"
device_class: door
filters:
- delayed_on_off: 1s
pin:
number: D6
inverted: false
mode: INPUT_PULLUP
# Enable logging
logger:
debug:
# Enable Home Assistant API
api:
password: ""
services:
- service: control_servo
variables:
level: float
then:
- servo.write:
id: lock_servo
level: !lambda "return level / 100.0;"
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Smart Lock Fallback Hotspot"
password: ""
captive_portal:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment