Door Bell Set for Home Assistant With ESP32 + ESP01

by Radim RKG Keseg in Circuits > Wireless

11286 Views, 13 Favorites, 0 Comments

Door Bell Set for Home Assistant With ESP32 + ESP01

20210519_200015.jpg
ESP01-DoorBell-set-complete.jpg
HA-DoorBell-set-diagram.jpg

Well, one day I had an issue with my doorbell, precisely I did not hear a postman bringing an important parcel. I realized, instead of a classic doorbell with a button by my entry door and a bell in the house, I could create something more sophisticated.

A doorbell with a camera notifying by different visual and audio signals on several places.

A standard scenario was a button and a ring, but then I started thinking could I enhance it a bit more.

Well what if I had a visual alarm on my desk, since when having video conference with a noise cancelling head set, I don't hear too much, rather saying nothing. It would be better if something starts blinking on my desk.

Then I expanded my thinking even more, if I had a gadget that blinks when someone presses a doorbell button, I could have a gadget that receives various signals and blinks based on a notification type.

Furthermore it could optionally inform me at each quarter and full on clock, eventually support a visual alarm.

If I had this gadget, I could make something a bit bigger that would serve as a wall clock with the extra features mentioned above.

Maybe I could so something universal that does optionally all.

Enough, you can find the result of my endeavor here in next steps.

Supplies

Appliances / Accessories

  • Home Assistant - running on a virtual machine or a raspbery https://www.home-assistant.io
    • with ESPhome addon installed (for ESP programming)
  • Wifi router
  • 3D printer
  • soldering station
  • cords
  • several 5V power adapters
  • USB to UART programmer

DoorBell - control

  • ESP32-CAM
  • (ESP01)
  • PIR sensor - HC-SR501
  • NeoPixel Ring - 12 LEDs
  • Microbutton

Bell - monitor

  • ESP01
  • NeoPixel Ring - 16 LEDs
  • Mini MP3 player break out
  • 3W amplifier
  • 3W Speaker 40mm

Optionally

Nudger - visual notifications

  • ESP01
  • NeoPixel Ring - 16 LEDs

Clock - visual notification

  • ESP01
  • NeoPixel Ring - 60 LEDs

DoorBell - Control

ESP32-DoorBell-Control-Scheme.jpg
ESP32-DoorBell-Control-internals.jpg
ESP32-DoorBell-Control-complete.jpg

Lets start with a controller, the part where a postman or any other regular visitor needs to press a button to let you know the one stands in front of your door.

we need following parts

  • ESP32-CAM
  • PIR sensor - HC-SR501
  • NeoPixel Ring - 12 LEDs
  • Microbutton

and connect them together as shown on the above picture

once connected we can program the ESP32 thru ESPhome and a yaml config file that could be found here esp32_cam_doorbell.yaml

From this time your doorbell control is ready to be used, however it would later need a bit of configuration in Home Assistant which automatically detects a new device and to add it after a few intuitive clicks to the a Home Assistant view.

In a mean while there is a chance to print off couple of parts for the doorbell "button".

The 3D models to print a case can be found here

all STL models with gcodes can be found here in 3D models

DoorBell Control - Without CAM

ESP01-DoorBell-Control-Scheme.jpg
ESP01-DoorBell-Control-internals.jpg
ESP32-DoorBell-Control-Scheme.jpg
ESP32-DoorBell-Control-complete.jpg

A simpler version of the controller, with a BUTTON, a PIR sensor, and a NEOPIXEL ring could be optionally created following way.

we need these parts

  • ESP01
  • PIR sensor - HC-SR501
  • NeoPixel Ring - 12 LEDs
  • Microbutton

and connect them together as shown on the above picture

once connected we can program the ESP01 thru ESPhome and a yaml config file that could be found here esp01_doorbell_button.yaml

From this time your doorbell control is ready to be used, however it would later need a bit of configuration in Home Assistant which automatically detects the a device and to add it after a few intuitive clicks to a Home Assistant view.

For this version there is no print model prepared yet, however if created later you would find those in the same repo mentioned bellow at the and of this section.

The most reliable option is to combine the ESP01 and ESP32 and split the responsibilities. In case the CAM stops operating the button controlled by ESP01 will still operate as expected.

You can combine the ESP01 and ESP32 program ESP32-CAM only (without microbutton, pir, neopixel connected) thru ESPhome using following config here

esp32_cam.yaml

In a mean while there is a chance to print off couple of parts for the doorbell "button".

The 3D models to print a case can be found here:

all STL models with gcodes can be found here 3D models

Bell

ESP01-DoorBell-Monitor-Scheme.jpg
ESP01-DoorBell-Monitor-internals.jpg
ESP01-DoorBell-Monitor-complete.jpg
NeoPixel-Nudger-web-config.jpg

In previous steps we have created our doorbell control, but we don't hear any notification, of course we could trigger other automations by that control but let's create a bell that clinks when someone presses the doorbell button.

we need following parts:

  • ESP01
  • NeoPixel Ring - 16 LEDs
  • Mini MP3 player break out
  • Micro SD card
  • 3W amplifier
  • 3W Speaker 40 mm

(and optionally to reduce a micro noise when nothing happens)

  • transistor 2N2222
  • resistor 470 ohm

and to connect them together as shown on the picture above.

Now we should program the device, of course we could use similar approach and to use ESPhome to program the ESP01, however from educational purposes I used another approach to program it thru Arduino IDE.

The code can be found here:

Arduino code for NeoPixel Nudge

We need to compile it and upload to ESP01 using universal USB-UART programmer or a specific one for ESP01 which is a bit more straight forward.

Anyway please keep attention to the code especially the NeoPixel-Nudge.ino

There are 2 defines in beginning, they look following way for the loud clinker
//#define SHOWCLOCK
#define PLAYSONG

in case you wish to use just a visual alarm, comment the PLAYSONG to read this
//#define SHOWCLOCK
//#define PLAYSONG

in case you wish to use a clock visual alarm with 60 LED NEOPIXEL ring uncomment both to read this
#define SHOWCLOCK
#define PLAYSONG

To print a case find the 3D designs here:

all STL models with gcodes can be found here 3D models

Don't forget to place an MP3 sound (or more sounds) to your SD card, without that it would play any sound. I personally found this sound interesting so for personal use they are fine could be the right choice doorbell-sound-effect.

Now you might ask, how to make your new device communicating to your Home Assistant?

After switching the device on, it will activate an Access point with a name like NeoPixel-Bell-Nudger-xxxxxx. Mark the xxxxxx number which represents last numbers of MAC address. Connect to the access point and set up your WiFi credentials so the new device can connect to your wifi. After saving the config, the device restarts and connects to your WiFi.

Use e.g. FING app to scan your network and find the new device (remember the xxxxxx represnts last part of MAC address to find the right device) . Scan thru open ports, the http port 80 should be open there. Connect to the IP of the device via browser and configure as shown on the picture above.

Well since the firmware uses MQTT, obviously there is need to have MQTT addon enabled and configured on your home assistant (seethe the next step).

After the bell nudger device has been configured all is prepared for the final touch and some automation thru your Home assistant.

Let's look at it in the next step.

Automation Setup

HA-Lovalace-Gadget-with-CAM.jpg

Let's add our Door Bell clinker/nudger to the Home Assistant. In case of our clinker created thru Arduino IDE, there is need to edit confiuguration.yaml by adding following parts (in case they already exist such as sensor: or homeassistatn: just adjust the sections accordingly)

mqtt:
  broker: 127.0.0.1
  port: 1883

sensor:
  - platform: mqtt
    state_topic: "nudge/ou_04"
    name: "esp_nudge_04"
    value_template: {{ value_json.state }}
    
homeassistant:  
  customize:
    sensor.esp_nudge_04:
      friendly_name: "Door Bell 04"

The other devices like ESP32-CAM flashed thru ESPhome should get automatically discovered at the moment they are connected to your network and you would find then in devices/entities of your Home Assistatnt.

This way we should have 2 new devices

  • doorbell ring
  • doorbell cam (with button, pir and neopixel ring entities )

or if you selected the option without cam

  • doorbell ring
  • doorbell button (with pir and led strip)

or in case of you were geeky and combined both options together and split the controller part to camera and button (ESP32 + ESP01) we should have 3 devices

  • doorbell ring
  • dorbell cam
  • doorbell button (with pir and neopixel ring entities)

Here comes the time we would create our own gadget on Home Assistant Lovelace view.

type: vertical-stack
cards:
  - type: vertical-stack
    cards:
      - type: grid
        cards:
          - type: button
            entity: switch.esp32_cam_doorbell_01_restart
            name: Restart
            show_state: false
            show_icon: true
          - type: button
            entity: script.doorbell_01_snapshot
            show_state: true
            tap_action:
              action: call-service
              service: script.doorbell_01_snapshot
              service_data: {}
              target: {}
            name: Snapshot
          - type: button
            entity: light.esp32_cam_doorbell_01_light
            name: Flash
            show_state: true
      - type: picture-entity
        entity: camera.esp32_cam_doorbell_01
        name: DoorBell Cam
        camera_image: camera.esp32_cam_doorbell_01
        show_state: false
  - type: grid
    cards:
      - type: button
        entity: binary_sensor.esp01_doorbell_01_button
        name: Doorbell Button
        show_state: true
      - type: button
        entity: weather.local_place
        show_state: true
      - type: button
        entity: light.esp01_doorbell_01_led_ring
        name: DoorBell NeoPixel
        show_state: true
        icon: 'mdi:ring'
        tap_action:
          action: none

All devices now work independently, and we need to set up an automation to make it doing what we expect.

When someone clicks a button on our doorbell control we would hear a door bell gong sound (or any other sound you placed on your SD card).

A simple automation can look following way:

A script to make the sound of doorbell by our "clinker"

alias: doorbell_01_ring
sequence:
  - service: mqtt.publish
    data:
      topic: nudge/in_04
      payload: '{ "color": "00ffff", sec: 5, song: 1, volume: 21 }'
mode: single
icon: 'mdi:doorbell-video'

A script that runs animation of a doorbell neopixel ring to let visually know back it passed thru your Home Assistant system.

alias: doorbell_01_feedback
sequence:
  - scene: scene.doorbellring_feedback
  - wait_template: ''
    timeout: '00:00:05'
    continue_on_timeout: true
  - scene: scene.doorbellring_feedback_off
mode: single
icon: 'mdi:hand'

Optionally a script to take a snapshot.

alias: doorbell_01_snapshot
sequence:
  - service: camera.snapshot
    target:
      entity_id: camera.esp32_cam_doorbell_01
    data:
      filename: >-
        /config/www/cam_captures/doorbell_01_{{ now().strftime("%Y%m%d-%H%M") }}.jpg
  - service: camera.snapshot
    target:
      entity_id: camera.esp32_cam_doorbell_01
    data:
      filename: /config/www/cam_captures/doorbell_01_last.jpg
mode: single
icon: 'mdi:camera'

Here comes the time to set automation that triggers all the scripts.

alias: DoorBell Rings
description: ''
trigger:
  - type: turned_on
    platform: device
    device_id: sensor.esp01_doorbell_01  #optionaly your esp32-cam
    entity_id: binary_sensor.esp01_doorbell_01_button
    domain: binary_sensor
condition: []
action:
  - service: script.doorbell_01_ring
  - service: script.doorbell_01_snapshot
  - service: script.doorbell_ring_feedback
mode: single

And the work is done !

I believe you can create another ways of automation. Most of them are clickable thru UI of your Home Assistant and with no need for complicated coding or yaml configuration.

Happy creating, tinkering and bastling ;)