Introduction: Smart Doorbell for HomeAssistant
So, I wanted a doorbell with the following features:
- Video from the door
- Two way audio
- Two buttons
- Integration with wall mounted tablet showing HomeAssistant UI
Some options came along like Doorbird (expensive and they do not have two-way audio calling using HTML5) and Ring doorbell (but I don't like a subscription, cloud based doorbell)
As a developer and tinkerer, I already finished some projects but this was by far one of the most difficult ones to complete. I had a lot of trouble getting the two-way audio working to a point where you can understand each other. This mainly because there is quite a lot of echo, ... . The idea comes from DoorPi, but with the SIP protocol, I had too much echo which made resulted in not understanding one-another.
Since my doorbell is completely protected from the elements, we are able to make the front in lasercut wood.
- Raspberry Pi 3 B or 3B+ (do not go for a Banana Pi with PoE build in as it does not support the standard Raspberry Pi CSI camera interface) = € 33,67
- Micro SD card = € 2,69
- Raspberry Pi fisheye camera = € 14,14
- PoE adapter = € 4,94
- RaspiAudio Mic + = € 24,69
- Access to 3D printer (and laser cutter)
- Buttons for the Doorbell
- A lot of time!
This adds up to a total of € 80,13.
Out of scope, the indoor station:
- HomeAssistant setup with an MQTT Broker
- Wall mounted Android Tablet
Step 1: Setup Raspberry Pi
I highly recommend you to use ethernet instead of Wifi. My audio quality improved a lot due to it. We will also be using UV4L since it supports webrtc and thus has echo-cancellation built-in. The Doorpi uses linphone, a SIP client and I was unable to get the echo cancellation working.
- Download Raspbian Stretch Lite and install it on the Micro SD card. Make sure you:
- enable ssh by creating an empty ssh file in the boot partition
- Run the following commands:
sudo apt-get update sudo apt-get upgrade
Enable the camera via raspi-config and make sure that the GPU has at least 192 MB of ram.
Follow the installation guide of RaspiAudio found at https://www.raspiaudio.com/raspiaudio-aiy
Follow the installation guide of UV4L found at https://www.linux-projects.org/uv4l/installation/.
Adjust the /etc/uv4l/uv4l-raspicam.conf file and make sure you adjust the following settings:
The most notable settings is probaby --enable-webrtc-video=no: this is because we will always stream the video from uv4l using h264 encoded mjpeg.
Using the following files located in /usr/share/uv4l/demos/doorpi/, you can already test the two-way audio and video.
- index.html (rename it from index.html5, needed to rename due to instructables upload requirements)
Browse to https://[ip-of-raspberrypi]:8888 and test if you can get the 2-way audio working.
The easiest way I found to get the doorbell-buttons working, is to attach them to the raspberry pi and use pi-mqtt-gpio to integrate it with HomeAssistant.
My configuration file is as follows:
mqtt:<br> host: x.x.x.x port: 1883 user: [username] password: [password] topic_prefix: "doorbell" gpio_modules: - name: raspberrypi<br> module: raspberrypi<br> cleanup: yes digital_inputs:<br> - name: button_1<br> module: raspberrypi<br> pin: 17<br> on_payload: "Off"<br> off_payload: "On"<br> pullup: yes<br> pulldown: no<br> - name: button_2<br> module: raspberrypi<br> pin: 27<br> on_payload: "Off"<br> off_payload: "On"<br> pullup: yes<br> pulldown: no
Do note that as there more ground pins available as 3.3V pins, I choose to use pullup GPIO pins and thus inverted my MQTT messages.
Step 2: Doorbell Box
- doorbell-back v1.stl: 3D printed box for raspberry pi and PoE adapter
- doorbell-front v1.svg: Laser cut face plate
- doorbell-micro v1.stl: 3D printed box containing mirophone wrapped with sound insulation, glued to face plate
Screw the raspberry pi in the attached screw holders and put the PoE adapter on the top right. Put the camera and the microphone in place (make sure to detach the microphone and make sure the hole of the microphone is well aligned with a hole in the face plate).
Step 3: HomeAssistant Integration
The following files allow for HomeAssistant integration:
- doorpi.yaml: package containing everything related to the doorbell including listening to MQTT messages and automations to play the chime when the doorbell is pushed
- www/doorpi/doorpi-card.js: lovelace doorpi card which needs the signalling.js and doorpi-camera-view.js
IMPORTANT: Do note that you must be running HomeAssistant with https/ssl as otherwise chrome will not allow you to access the audio devices.
Step 4: Happy Doorbell-calling!
That's it, you should now be able to call someone via the doorbell and HomeAssistant will automatically switch to the doorbell card. There you can decide to accept or ignore the doorbell.