Last active
June 16, 2023 00:32
-
-
Save jap/ca1c7ee0413fd121b312e590d26480ff to your computer and use it in GitHub Desktop.
esphome powered imperial march doorbell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# writtten by Jasper Spaans, | |
# based on https://frenck.dev/diy-smart-doorbell-for-just-2-dollar/ | |
esphome: | |
name: doorbell_v2 | |
platform: ESP8266 | |
board: esp01 | |
# WiFi connection, correct these | |
# with values for your WiFi. | |
wifi: | |
ssid: XXX | |
password: YYY | |
# Enable logging. | |
logger: | |
# Enable Home Assistant API. | |
api: | |
# Enable over-the-air updates. | |
ota: | |
# Enable Web server. | |
web_server: | |
port: 80 | |
# Sync time with Home Assistant. | |
time: | |
- platform: homeassistant | |
id: homeassistant_time | |
# Text sensors with general information. | |
text_sensor: | |
# Expose ESPHome version as sensor. | |
- platform: version | |
name: Doorbell ESPHome Version | |
# Expose WiFi information as sensors. | |
- platform: wifi_info | |
ip_address: | |
name: Doorbell IP | |
ssid: | |
name: Doorbell SSID | |
bssid: | |
name: Doorbell BSSID | |
# Sensors with general information. | |
sensor: | |
# Uptime sensor. | |
- platform: uptime | |
name: Doorbell Uptime | |
# WiFi Signal sensor. | |
- platform: wifi_signal | |
name: Doorbell WiFi Signal | |
update_interval: 60s | |
# Global to store the on/off state of the chime and march flag | |
globals: | |
- id: chime | |
type: bool | |
restore_value: true | |
initial_value: 'true' | |
- id: march | |
type: bool | |
restore_value: true | |
initial_value: 'true' | |
# Exposed switches. | |
switch: | |
# Switch to restart the doorbell. | |
- platform: restart | |
name: Doorbell Restart | |
# Switch to turn on/off the chime. | |
- platform: gpio | |
id: relay | |
inverted: true | |
name: Doorbell Chime | |
pin: GPIO0 | |
# Switch to turn on/off chime when | |
# doorbell button is pushed. | |
# | |
# It creates a "virtual" switch based | |
# on a global variable. | |
- platform: template | |
name: Doorbell Chime Active | |
id: chime_active | |
restore_state: false | |
turn_on_action: | |
- globals.set: | |
id: chime | |
value: 'true' | |
turn_off_action: | |
- globals.set: | |
id: chime | |
value: 'false' | |
lambda: |- | |
return id(chime); | |
- platform: template | |
name: March | |
id: march_active | |
restore_state: true | |
turn_on_action: | |
- globals.set: | |
id: march | |
value: 'true' | |
turn_off_action: | |
- globals.set: | |
id: march | |
value: 'false' | |
lambda: |- | |
return id(march); | |
# A rhythmic interpretation of the Emperor's March | |
script: | |
- id: march_script | |
then: | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.58s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.58s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.58s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.38s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.18s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.58s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.38s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
- delay: 0.18s | |
- switch.turn_on: relay | |
- delay: 0.02s | |
- switch.turn_off: relay | |
# Binary sensor representing the | |
# Doorbell button push. | |
binary_sensor: | |
- platform: gpio | |
id: button | |
name: Doorbell Button | |
pin: | |
# Connected to GPIO on the ESP-01S. | |
number: GPIO2 | |
mode: INPUT_PULLUP | |
inverted: true | |
filters: | |
# Small filter, to debounce the button press. | |
- delayed_on: 25ms | |
- delayed_off: 25ms | |
on_press: | |
# Only turn on the chime when it is active. | |
then: | |
if: | |
condition: | |
and: | |
- switch.is_on: chime_active | |
- not: | |
- script.is_running: march_script | |
then: | |
if: | |
condition: | |
switch.is_on: march_active | |
then: | |
- script.execute: march_script | |
else: | |
- switch.turn_on: relay | |
on_release: | |
# On release, turn of the chime. | |
- switch.turn_off: relay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment