Skip to content

Instantly share code, notes, and snippets.

@frenck
Last active March 31, 2024 13:29
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save frenck/0af30b05f7c98d17219548b46a03df21 to your computer and use it in GitHub Desktop.
Save frenck/0af30b05f7c98d17219548b46a03df21 to your computer and use it in GitHub Desktop.
Blog: For just $2, convert any existing wired doorbell into a smart doorbell; using ESPHome and Home Assistant: https://frenck.dev/diy-smart-doorbell-for-just-2-dollar/
---
esphome:
name: doorbell
platform: ESP8266
board: esp01_1m
# WiFi connection, correct these
# with values for your WiFi.
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# 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
globals:
- id: chime
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);
# 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:
- switch.is_on: chime_active
then:
- switch.turn_on: relay
on_release:
# On release, turn of the chime.
- switch.turn_off: relay
---
# This automation triggers when the doorbell button is pushed
# and out the front door camera stream to the tv.
#
automation:
- alias: "Doorbell Camera"
trigger:
platform: state
entity_id: binary_sensor.doorbell_button
to: 'on'
action:
- service: camera.play_stream
data:
entity_id: camera.front_door
media_player: media_player.living_room_tv
---
# Turns off the doorbell chime after 8pm.
# Turns it on again in the morning @ 7am.
#
automation:
- alias: "Doorbell off after 8pm"
trigger:
platform: time
at: "20:00:00"
action:
service: switch.turn_off
entity_id: switch.doorbell_chime_active
- alias: "Doorbell on after 7am"
trigger:
platform: time
at: "07:00:00"
action:
service: switch.turn_on
entity_id: switch.doorbell_chime_active
---
# This automation triggers when the doorbell button is pushed
# and sends out a notification to our Apple iPhones/watches.
#
automation:
- alias: "Doorbell Notifications"
trigger:
platform: state
entity_id: binary_sensor.doorbell_button
to: 'on'
action:
- service: notify.mobile_app_frencks_iphone
data:
title: Doorbell
message: Ding dong! Someone is at the door!
data:
attachment:
content-type: jpeg
url: http://tiptag.com.ar/wp-content/uploads/2018/06/timbre1.jpg
- service: notify.mobile_app_ninja_iphone
data:
title: Doorbell
message: Ding dong! Someone is at the door!
data:
attachment:
content-type: jpeg
url: http://tiptag.com.ar/wp-content/uploads/2018/06/timbre1.jpg
@a8ree
Copy link

a8ree commented Mar 17, 2021

Hi
I'm trying to set up this project but something is going wrong when I write

INFO Reading configuration config/frontdoor_doorbell.yaml...
INFO Detected timezone 'GMT' with UTC offset 0 and daylight savings time from 28 March 01:00:00 to 31 October 02:00:00
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d config/doorbell
Processing doorbell (board: esp01_1m; framework: arduino; platform: espressif8266@2.6.2)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20704.0 (2.7.4) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
Library Manager: Installing Update
Library Manager: Already installed, built-in library
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ArduinoJson-esphomelib> 5.13.3
|-- <ArduinoJson-esphomelib> 5.13.3
Retrieving maximum program size .pioenvs/doorbell/firmware.elf
Checking size .pioenvs/doorbell/firmware.elf
RAM:   [=====     ]  47.7% (used 39088 bytes from 81920 bytes)
Flash: [====      ]  43.2% (used 442680 bytes from 1023984 bytes)
========================= [SUCCESS] Took 2.46 seconds =========================
INFO Successfully compiled program.
INFO Running:  esptool.py --before default_reset --after hard_reset --baud 460800 --chip esp8266 --port /dev/cu.usbserial-A50285BI write_flash 0x0 config/doorbell/.pioenvs/doorbell/firmware.bin
esptool.py v2.8
Serial port /dev/cu.usbserial-A50285BI
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 60:01:94:0e:4a:c1
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 1MB
Compressed 446832 bytes to 305385...
Wrote 446832 bytes (305385 compressed) at 0x00000000 in 7.1 seconds (effective 501.8 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from /dev/cu.usbserial-A50285BI with baud rate 115200

It doesn't ever boot / join wifi.

any ideas?

Cheers

@yann1420
Copy link

Hi Frenck, this page seems unavailable [(https://frenck.dev/diy-smart-doorbell-for-just-2-dollar/)]
Cheers.

@Flipperkastje
Copy link

Hello Frenck,

I like your way of presenting this hardware project a lot. But when I validate the yaml code, there is a option "restore_state" used which is not valid anymore. What should I change to get it working?

Thank you for all your effort in sharing !!

I get this error when validating :

INFO ESPHome 2023.11.4
INFO Reading configuration /config/esphome/Doorbell.yaml...
INFO Detected timezone 'Europe/Amsterdam'
Failed config

switch.template: [source /config/esphome/Doorbell.yaml:81]
platform: template
name: Doorbell Chime Active
id: chime_active

The restore_state option has been removed in 2023.7.0. Use the restore_mode option instead.
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);

@hax4dazy
Copy link

@Flipperkastje I've managed to fix the issue by just editing line 81 to be

    restore_mode: 'RESTORE_DEFAULT_OFF'

This seems to at least make the code compile which is nice but I'm unsure if this actually is a "fix" for the issue as I'm unsure what the original option even does

@jevburchell
Copy link

@hax4dazy thanks for posting the above, I hit exactly the same problem as @Flipperkastje during Yaml Validation.

@frenck are you aware of the above coding problem? It looks like v2023.7.0 has changes which invalidate the "restore_state" command

@Duivelmolen
Copy link

@Flipperkastje I've managed to fix the issue by just editing line 81 to be

    restore_mode: 'RESTORE_DEFAULT_OFF'

perfect thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment