MUO logo

Build a DIY Smart Doorbell for Home Assistant With Push Notifications

Doorbell being pushed by a finger
Source: https://www.pexels.com/photo/person-pressing-white-button-8550100/
Free to use, NAR
Sign in to your MUO account

A smart doorbell is a convenient and innovative way to enhance your convenience and home security and find who is at your door, even when you are not at home.

Using two ESP8266 boards, we will build a fully functional Wi-Fi smart doorbell that integrates with Home Assistant smart home automation software and sends push notifications to your smartphone whenever someone rings the doorbell. This works both locally and remotely.

Things You Will Need

You will need the following components to build the DIY Wi-Fi smart doorbell.

  • 2 x ESP8266 microcontroller boards, such as NodeMCU or D1 Mini, will serve as the brain of the doorbell
  • Doorbell switch
  • Micro USB power supply
  • DFPlayer Mini (MP3 player module)
  • microSD card (512MB or larger)
  • 2W or 3W (1" or 2" wide) speaker for the sound output
  • 2.4GHz Wi-Fi network
  • Home Assistant server running on a Raspberry Pi, or you may install Home Assistant on an x86 PC.
  • Jumper wires to connect all the components

Step 1: Compile the Firmware

We will compile two different firmwares:

  • Smart bell speaker firmware (receiver)
  • Smart bell switch firmware (transmitter)

To compile the smart bell speaker and smart bell switch firmware, follow these steps:

  1. If not already installed, install ESPHome in Home Assistant: go to Settings > Add-Ons and click ESPHome.
    [画像:install esphome in home assistant] Credit: Screenshot by Ravi. NAR
  2. Click Open Web UI and then click New Device.
  3. Name the device anything you want. For this tutorial, we called it "smart-bell-speaker". Click Next > Skip this step.
  4. Then select ESP8266 board from the options and then click Skip.
  5. This will see a new configuration named smart-bell-speaker.
  6. Similarly, create one more configuration and name it smart-bell-switch.
  7. Once the configurations are created, open the smart-bell-speaker configuration by clicking on the Edit button.
  8. Then paste the following code below the captive_portal: text.
    uart:
     tx_pin: GPIO3
     rx_pin: GPIO1
     baud_rate: 9600
    dfplayer:
     on_finished_playback:
     then:
     logger.log: 'Playback finished event'
    api:
     encryption:
     key: "kQ5tP73N1pOl6XDYtq5RY15IaPsXjTg2A9g5nzHPejE="
     services:
     - service: dfplayer_next
     then:
     - dfplayer.play_next:
     - service: dfplayer_previous
     then:
     - dfplayer.play_previous:
     - service: dfplayer_play
     variables:
     file: int
     then:
     - dfplayer.play: !lambda 'return file;'
     - service: dfplayer_play_loop
     variables:
     file: int
     loop_: bool
     then:
     - dfplayer.play:
     file: !lambda 'return file;'
     loop: !lambda 'return loop_;'
     - service: dfplayer_play_folder
     variables:
     folder: int
     file: int
     then:
     - dfplayer.play_folder:
     folder: !lambda 'return folder;'
     file: !lambda 'return file;'
     - service: dfplayer_play_loop_folder
     variables:
     folder: int
     then:
     - dfplayer.play_folder:
     folder: !lambda 'return folder;'
     loop: true
     - service: dfplayer_set_device_tf
     then:
     - dfplayer.set_device: TF_CARD
     - service: dfplayer_set_device_usb
     then:
     - dfplayer.set_device: USB
     - service: dfplayer_set_volume
     variables:
     volume: int
     then:
     - dfplayer.set_volume: !lambda 'return volume;'
     - service: dfplayer_set_eq
     variables:
     preset: int
     then:
     - dfplayer.set_eq: !lambda 'return static_cast<dfplayer::EqPreset>(preset);'
     - service: dfplayer_sleep
     then:
     - dfplayer.sleep
     - service: dfplayer_reset
     then:
     - dfplayer.reset
     - service: dfplayer_start
     then:
     - dfplayer.start
     - service: dfplayer_pause
     then:
     - dfplayer.pause
     - service: dfplayer_stop
     then:
     - dfplayer.stop
     - service: dfplayer_random
     then:
     - dfplayer.random
     - service: dfplayer_volume_up
     then:
     - dfplayer.volume_up
     - service: dfplayer_volume_down
     then:
     - dfplayer.volume_down
  9. Also, edit the Wi-Fi SSID and password secrets with your Wi-Fi name and password. Make sure where you are going to install the smart-bell-speaker and smart-bell-switch has decent Wi-Fi network coverage.
    wifi: 
     ssid: "MyWiFiName" 
     password: "MyWiFiPassword"
  10. Click Save and then click Install.
  11. Choose Manual download. This will start the firmware compilation. Once compiled, download and save the firmware on your system.
  12. Now open the smart-bell-switch project, change the Wi-Fi secrets and then paste the following code below the captive_portal:
    binary_sensor:
     - platform: gpio
     name: "Smart Bell Switch"
     pin:
     number: 4
     mode: INPUT_PULLUP
     inverted: True
     on_press:
     - switch.toggle: relay1
     internal: True
    switch:
     - platform: gpio
     name: "Smart Door Bell"
     icon: 'mdi:bell'
     id: relay1
     pin:
     number: 2
     mode: OUTPUT
     inverted: True
  13. Click Save and then click Install.
  14. Choose Manual download. After the compilation, the firmware will automatically start downloading. Save both firmware on the Desktop.

Step 2: Upload MP3 Sound Files to a MicroSD card

Take a small-capacity microSD card (as low as 512MB will work). Connect it to your PC. Download your favorite bell sounds from the internet, or you can record your own or your voice, and save them as MP3 files on the microSD card. Make sure to name these files as 1.mp3, 2.mp3, etc.

Step 3: Flash the Firmware to the ESP8266 Microcontroller

To flash the firmware, connect the NodeMCU or D1 Mini to the PC using a micro USB cable and then follow these steps:

  1. Download and launch ESPHome-Flasher tool.
  2. Choose the COM port and then click Browse to select the firmware file you downloaded in the previous step.
  3. Click Flash ESP. Wait for the firmware to flash.
  4. Once done, the device will automatically connect to the Wi-Fi network.

Follow the same steps to flash the firmware on the two ESP8266 boards.

Step 4: Wiring ESP8266 Board with DFPlayer and Speaker

Refer to the following diagram to wire the DFPlayer with the ESP8266 on which you flashed the smart-bell-speaker firmware.

You can use jumper wires to make these connections and use a soldering iron to connect the speaker to the DFPlayer (MP3 player module).

Once everything is connected, use two jumper wires (male to female) and connect them to the smart-bell-switch ESP8266 board. You need to connect one wire to the D2 pin on the NodeMCU or D1 Mini ESP8266 board and another to the 3V or 3.3V pin. Then connect the other two ends to your traditional push-button bell switch, as shown in the diagram below.

Make sure to double-check the wiring before proceeding.

Step 5: Add Devices to Home Assistant

We need to add both devices to Home Assistant. To do so, follow these steps:

  1. Go to Settings > Devices & Services.
  2. You will see the smart-bell-switch and smart-bell-speaker (if powered on) in the Discovered Devices list.
  3. Click Configure > Submit.
  4. Choose an area from the drop-down and click Finish.
  5. Similarly, power on and add the smart-bell-speaker device to your Home Assistant.

Step 6: Create Automation for Custom Bell Sound and Push Notifications

To enable push notifications for your smart DIY Wi-Fi smart doorbell, you need to create an automation in the Home Assistant. To create, one, follow these steps:

  1. In Home Assistant, go to Settings > Automations & Scenes.
  2. Click Create Automation > Create new automation.
  3. Click Add Trigger and select Device.
  4. Choose smart-bell-switch and then select Smart Door Bell turned on in the Trigger drop-down.
  5. Click Add Action and select Call Service.
  6. Choose ESPHome: smart_speaker_dfplayer_play from the drop-down.
  7. In the file, type 1, 2 or 3 for whichever MP3 bell sound you want to play.
  8. Then click Save.
  9. Give the automation a name and then click Save again.
  10. For push notifications on your phone, install the Home Assistant app on your smartphone, sign in to your Home Assistant, and then click Add Action in the automation window.
  11. Select Call Service and choose Notifications: Send a notification via mobile_app_YourPhone.
  12. Type a message that you want to receive in the notification and click Save.

If you now push the doorbell button, the bell sound will play from the smart-bell-speaker. You can check the logs for more details if automation is working.

Make a Smart Door Bell Smarter

Building your own DIY Wi-Fi smart doorbell using ESP8266 microcontroller boards and Home Assistant is a rewarding and cost-effective project.

Once the basic functionality of the DIY Wi-Fi smart doorbell is working correctly, you can add a CCTV IP camera, and integrate with Home Assistant using Frigate NVR to create advanced home automation and improve home security. You may also integrate a PIR sensor or a touch capacitive sensor instead of a traditional doorbell switch. The possibilities with Home Assistant are endless.

AltStyle によって変換されたページ (->オリジナル) /