The Ultimate Home Assistant / ESPHome Doorbell
by intuitiv in Workshop > 3D Printing
7015 Views, 32 Favorites, 0 Comments
The Ultimate Home Assistant / ESPHome Doorbell
Over 20 years ago we installed a super-modern doorbell system in our house. State-of-the-art year 2000. Based on a bus-system. Great design, lots of plastic. Now, the time was over for the old plastic housing. The life span of that old plastic was not the best. We need a replacement.
Having home assistant running now for over a year my decision was to add something new, something smart to the new doorbell housing.
I've added a lot of these esp-devices connected over wireless with sensors and actors over the last year with my home assistant installation. So I've planned doing the same with the new doorbell.
Having a new 3D-printer a new housing is the ideal operation area for this tool.
This is a project for 3d printing and electronics with soldering.
Supplies
For the housing I have used ASA filament. Additionally I used TPU for a seal between the lid and the base.
For the electronics I used:
- esp32cam
- esp32
- PIR-Sensor
- OLED display
- RGB ring light with ws812 controller
- a doorbell button with led illumination made of stainless steel
- a relay
- a power adapter 24V / 1.5 A for DIN rail
- a sluggish fuse for 1.5 A
- a step-down converter for the power supply of the esp-stuff in the doorbell housing
- some cables
- some terminal blocks
You need standard tools for electronics and - of course - we will do some soldering.
If you want to add a DIN rail power supply of your own you have to work with high voltage. Be careful! You do it at your own risk. You have to know what you do.
The Idea of New Functionalities
... and the compatibility to the existing system.
We have a doorbell. It works without the internet. You press a button and it rings. This is a functionality we would like to maintain. But nevertheless new functionalities offered by a smart home automation should be implemented.
Some fancy gizmos like a display for the name you can use for displaying any kind of text, too. An rgb light for feedback to the person standing infront of your house. Some additional sensors like a pir and a cam.
Using ESPhome with esp32 and esp32cam the transport of the data will be over local wifi you just need a power supply. This will be realized using a power supply for a DIN rail and step-down converter. Which is much more efficient than the old 78xx-pieces.
Designing the Doorbell Housing
We had an old doorbell housing from siedle attached on a stainless steel plate at the entry of our ground. I would like to use it for attaching the new housing. My printer (Prusa Mini) can print maximum 18 cm x 18cm x 18cm. So I have to split the construction up into two parts. I designed two boxes you can push together with a routing for the cables.
The upper part contains the step-down converter, the esp32cam, the esp32 the pir. The lower part contains the bell button, the rgb led ring and the possibility attaching sensors for the letter box later on.
For the printing I've used asa filament. This should be thermal and uv resistant. I hope the lifespan is more than a few years. For the sealing I've used tpu.
Some words to the files attached (the descriptions are all in german...)
Klingelgehäuse Unterteile_unten / _oben: main body parts with some support for attaching the electronics
Klingelgehäuse Deckel_unten / _oben: lids for the body parts with cutouts for the pir, the cam and the button. Also some support when pressing the bell button the housing will not be deformed
Klingelgehäuse_Dichtung: you need this two times, printed in tpu
Klingelgehäuse Deckel unten_Ring: print this in transparent petg (I haven't found transparent asa)
Unterlage Klingelknopf: depending of the thickness of the sealing you are using there must be a small underlay at the support for the bell button. I've printed this in tpu and glued it under the three supports for the bell button.
Kabeldurchführung: this is for my extension coming this year connecting some sensors to the letter box. Therefor you have to drill a hole in the lower body part for the cabeling.
Some hints for printing the parts:
Use a housing around your printer for printing asa. It depends on your printer. I have positive effects. I use a simple carton big enough for the printer during doing his job (see photo attached).
I used a big brim around the body parts, about 10mm outside, because the plastic deforms when cooling and comes out not flat.
For the lids I used a little support. Scraping away the support after the print the nice structures appears (see photo).
First Print for Testing and Adjusting
It took awhile adjusting the design of all the parts. Especially using different types of material was a challenge. Even if you have the same dimension - they do not fit.
After some adjusting everything is fine now.
The Wiring of the Electronics
As usual with all this esp-stuff it is quite easy. You just connect the electronic parts with the power supply and the sensor outputs to the main boards.
Why do I use two esp boards? Processing pictures takes a lot of computing power of these small devices and I would be independent with possibilities attaching to the electronics. The esp32cam has only a limit amount of i/o ports available. And who knows you can nearly attach whatever sensor you want.
The esp32cam just needs power supply.
The bell button, the pir and the led ringlight goes directly to the i/o ports of the esp32 (you can see it in the code). For the oled display I use I2C bus, two cables you have to connect.
For the power supply I had the luck finding two unused cables in the old wiring. It was a bunch of cables and a lot of analysing which cable does what. So I fonund the wire for the bell button and another one for triggering an outdoor light at the house using a timer function in the old electronic (see the photo for the old wiring chaos).
The power supply now consist of an integrated switching power supply for a DIN rail sending 24V DC to the entry area. Then I use a step down converter in the doorbell housing generating 5V DC stable. You can use a switching power supply with 5 V but I was unsure with the length of the cable and the voltage drop on a cable over 30m.
For testing purposes you can do the wiring on your "crafting table". That's a big advantage putting the electronics together this way.
Afterwards I put everything in the body parts, fixed the small boards with screws and hot glue.
Programming the Devices With ESPHome
This is the yaml for the esp32 webcam:
esphome:
name: espcam03
platform: ESP32
board: esp32dev
################################################################################
# Cam03
################################################################################
wifi:
networks:
- ssid: <your ssid>
password: <your password>
manual_ip:
static_ip: <your ip>
gateway: <your gateway>
subnet: <your subnet>
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
# Ai Thinker Camera
esp32_camera:
external_clock:
pin: GPIO0
frequency: 20MHz
i2c_pins:
sda: GPIO26
scl: GPIO27
data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
vsync_pin: GPIO25
href_pin: GPIO23
pixel_clock_pin: GPIO22
power_down_pin: GPIO32
# Image settings
name: Cam03
max_framerate: 24 fps
idle_framerate: 0.2 fps
resolution: SVGA
horizontal_mirror: False
vertical_flip: False
# Web Server
esp32_camera_web_server:
- port: 8080
mode: stream
- port: 8081
mode: snapshot
#Flashlight
output:
- platform: gpio
pin: GPIO4
id: gpio_4
light:
- platform: binary
output: gpio_4
name: Cam03Licht
switch:
- platform: restart
name: "restart_espcam03"
This is a standard definition you can find in a lot of articles concerning esphome connection the esp32webcam with home assistant. Enabling the snapshot port I can write a routine taking a snapshot when the ring button is pressed and sending the photo via telegram to my smartphone. I will explain later in my automations.
Here is the yaml for the esp32 controlling the button, the ring light and the rest of the electronics:
esphome:
name: esp26klingel
esp32:
board: nodemcu-32s
framework:
type: arduino
################################################################################
# KlingelBot Vorplatz
################################################################################
wifi:
networks:
- ssid: <your ssid>
password: <your password>
manual_ip:
static_ip: <your ip>
gateway: <your gateway>
subnet: <your subnet>
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
# I2C Definition
i2c:
sda: GPIO21
scl: GPIO22
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
rotation: 180°
lambda: |-
// Draw rectangle
// it.rectangle(0, 0, 128, 64);
it.print(2, 12, id(kaushanscript), "<your name here>");
font:
# gfonts://family[@weight]
- file: "gfonts://Kaushan Script"
id: kaushanscript
size: 33
# Fast LED
light:
- platform: fastled_clockless
rgb_order: GRB
chipset: WS2812
pin: GPIO32
num_leds: 12
name: "esp26_Doorbell_Light"
binary_sensor:
# Klingeltaster
- platform: gpio
pin:
number: GPIO33
mode:
input: true
pullup: true
name: "esp26_Klingel"
# Briefkasten-Sensoren
# Briefkastenklappe
- platform: gpio
pin:
number: GPIO25
inverted: true
mode:
input: true
pullup: true
name: "esp26_Briefkastenklappe"
# Briefkastentür
- platform: gpio
pin:
number: GPIO26
inverted: true
mode:
input: true
pullup: true
name: "esp26_Briefkastentuer"
# PIR
- platform: gpio
pin:
number: GPIO27
mode:
input: true
pullup: true
name: "esp26_PIRDetection"
switch:
# Aussenlicht
- platform: gpio
pin: GPIO14
id: relay_licht
- platform: template
name: "esp26_Aussenlicht"
turn_on_action:
- switch.turn_on: relay_licht
- delay: 500ms
- switch.turn_off: relay_licht
A short description:
I use an oled display for displaying the name at the doorbell housing. With the display you are free changing the name to a message or whatever. I've searched for a font that looks nice to us and I found one with the Google fonts. See the code how to implement it.
I use a rgb ring light as an optical feedback to the person ringing at the door. It's a nice effect let the ring "glow" after pressing the button. And you know something happens and there is no need pressing the button many times. For the automation to this - later on.
The bell button is a binary sensor. It is possible because I use a button with two separate contacts. One as opener one as closer. The one closing is connected to the original bell wiring for the reason if the network is failing. The other one I use for the home automation. The code definition there is for the opener.
I defined two sensors for the letter box. One for the slot and one for the door. (This is something I will realize this spring waiting for warmer outdoor temperatures)
At least we have a pir sensor and a relay connected for detecting persons and switching the light outside the house. The old system offers a timer function so I just use the relay instead of the old switch. The code is the simulation of pressing and releasing the switch.
Implement Everything in Home Assistant
At the moment I use two automations. One is for the light ring glowing after pressing the doorbell button the other one takes a snapshot from the cam and sends it via telegram to my smartphone.
For the first I use this:
alias: Klingel Feedback
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.esp26_klingel
from: "off"
to: "on"
for:
hours: 0
minutes: 0
seconds: 0
condition: []
action:
- service: scene.turn_on
data: {}
target:
entity_id:
- scene.klingellicht_yellow
- choose:
- conditions:
- condition: state
entity_id: schedule.alexasprachausgabe
state: "on"
sequence:
- service: media_player.play_media
data:
media_content_type: sound
media_content_id: amzn_sfx_doorbell_01
target:
entity_id: media_player.dot1
- service: notify.alexa_media_dot1
data:
data:
type: tts
message: |
{% set rm1 = [ "Es hat geklingelt ",
"Besuch ist da ",
"Da steht jemand draussen ",
"Achtung, ein ungbetener Gast " ]
| random %}
{% set rm2 = [ "Vielleicht.. vielleicht auch nicht.",
" .. Erst mal schauen. ",
"Der Postbote, Amazon, oder jemand wichtiges. ",
"Ich konnte die Person leider nicht genau erkennen. ",
"Denke ich zumindest. ",
"Nur mal so nebenbei." ]
| random %}
{{ '{} .. {}'.format(rm1, rm2) }}
default: []
- delay:
hours: 0
minutes: 0
seconds: 2
milliseconds: 0
- service: light.turn_off
data: {}
target:
entity_id:
- light.esp26_doorbell_light
mode: single
For the light ring glowing I use a scenes defining the state. For on I have defined a yellow color for the ring with 50%. This is enough for daylight and not to bright in the night. Maybe you could change color or intensity depending on the time of the day. Additionally to the standard doorbell we still use our Alexa. It rings and says some random stuff. I like these random phrases. The more you define the better.
I use a schedule for Alexa talking or not (alexasprachausgabe). So it will be quite during night time.
The next is for sending a photo via telegram.
You have to define a folder where to store the picture. I always name it the same so it will be overwritten every time before being sent.
You have to set up the telegram integration with all the bot magics. Having this done you can use the chat id for this routine.
alias: Klingelbild
description: Sendet CamBild Klingel A21S Stefan abwesend
trigger:
- platform: state
entity_id:
- binary_sensor.esp26_klingel
from: "off"
to: "on"
condition: []
action:
- service: notify.mobile_app_stefan_a21s
data:
message: Klingel
data:
entity_id: camera.cam_vorplatz_axxon0
- service: notify.telegram_stefan
data:
message: Es klingelt
title: "# Klingel"
- service: camera.snapshot
data:
filename: /config/www/klingelbild.jpg
target:
entity_id: camera.cam03
- service: telegram_bot.send_photo
data:
file: /config/www/klingelbild.jpg
target: <your chat id>
caption: Klingelbild
mode: single
I defined three notifications. The first ist for the home assistant app. The next is a text message for telegram and the third ist the photo being taken, here klingelbild.jpg.
Adjust it to your needs.
Assembling the New Doorbell Outside
The housing s desinged for being screwed together with small screws (about M1.5, M2). The construction is not that waterproof as IP67. The sensors and the display are just pressed against the lid. If you have heavy rain directly on the front side it will flow in. You can seal the parts with some silicone for more stability.
The printed seal will help a little bit getting the moisture out of the housing.
The plastic parts can be glued with superglue.
Having Fun
Everything works fine. Our Alexa shouts out when someone rings the bell and I get some photos on my smartphone.
Even with low temperatures this winter (about -10°C) the system works perfect.
Additional Possibilities
A lot of i/o ports of the esp32 remain unused for now. You can attach more sensors if you want. An ldr for checking the light intensity outside, a dht22 for getting temperature and humidity outside. Just for mention two possibilities. Or you can attach an additional cob led for illuminating the path to your house during night time.
It depends on you...