I've been working from home a lot more recently, so I've been opting to get packages delivered straight to my home instead of the office. Since I need to sign for some packages myself, I need a reliable way to hear when someone is at the door. Now they can press a button outside, which triggers a notification and plays a doorbell chime inside the house.
The obvious fix for this is to buy a simple RF doorbell and install it, however...
The interaction flow above is similar to how the Mailbox sensor and Bedside lamp button operate, but this time the Raspberry Pi is connected directly to an external speaker
It needs to be clear that the button is actually a doorbell, so I decorated it with a 3D printed cap with a 'ringing bell' silhouette from the Material Design Icons set. This is just hot-glued to the button face, making the entire cap pressable.
Home Assistant offers a few integrations for playing audio. I tried the Music Player Daemon and VLC integrations, but settled on the low-fi Shell Command with aplay
due to its speed and minimalism. The only problem with using aplay
is that it only accepts unencoded waveform audio.
An easy workaround is to transcode audio files manually before using them: ffmpeg -i input.mp3 output.wav
.
In this example, I'm using sound_file
as a parameter to make the play_sound
command
reusable. My Raspberry Pi has a USB audio card connected, but for the speaker I want to use the onboard audio
card
(which is aliased as 'sysdefault').
$ cat ${HOME_ASSISTANT}/configuration.yaml
...
shell_command:
play_sound: 'aplay -D sysdefault {{ sound_file }}'
...
Here, I'm using a new script to handle the "doorbell pressed" notification actions, to keep them decoupled from the automation trigger.
$ cat /home/homeassistant/.homeassistant/scripts.yaml
...
notify_doorbell_pressed:
alias: Notify doorbell pressed
sequence:
- service: shell_command.play_sound
data:
sound_file: /home/pi/puzzle-solved.wav
- service: notify.notify_pushbullet
data:
message: Doorbell was pressed
...
Finally, the automation simply waits for a single
click trigger, which fires off the
notify_doorbell_pressed
script above.
$ cat /home/homeassistant/.homeassistant/automations.yaml
...
- id: doorbell_pressed
alias: Doorbell pressed
trigger:
- entity_id: sensor.0x00158d0002c41211_click
platform: state
to: single
action:
- service: script.notify_doorbell_pressed
...
This serves as a sensible first cut of a doorbell. Next, I'm keen to include some behaviours from other smart doorbell solutions, such as an intercom.
If you have any feedback or questions related to this article, please reply to my post on Twitter.
This article is part of the Home automation set.