Playing UniFi G4 Doorbell Chime through Sonos with Home Assistant


In February 2020 I made a big upgrade to the network at my house. While there isn't a lot of high bandwidth usage happening here I have been working from home since 2014 and due to the pandemic my wife had also been working from home. WiFi coverage had always been spotty and unreliable. We also had a few Ring products throughout the house including their Video Doorbell Pro and chime. Once I made the decision to upgrade I went all in on Ubiquiti's UniFi line of products for both networking and video security replacing all the networking and Ring devices in the house.

After a few days of running new ethernet drops, installing equipment, and getting things configured I was left with a setup I was happy with but there was one issue. Since we didn't have a traditional wired doorbell chime, we had no way of being alerted of someone pressing the button on the G4 doorbell other than receiving a notification on our phones. Ideally, like a traditional doorbell, we'd hear some audible notification in the house.

I set out to find a solution to this. I thought through and tried a few options but it turned out I didn't need to try or purchase anything else as I already had what I needed to accomplish what I was looking for.

Attempt 1: Traditional Doorbell Chime

This was always going to be my backup solution but I really didn't want to do it as it would require me to buy and wire in a traditional doorbell transformer and chime. With the current state of IoT devices and services I knew there had to be another way so I was reluctant to settle on this option for as long as it could.

Newhouse Hardware CHM1 Door Bell Chime, White
Newhouse Hardware CHM1 Door Bell Chime, White
Doorbell Transformer Compatible with Ring Video Doorbell Pro 16v 30va Hardwired Door Chime Transformer
Doorbell Transformer Compatible with Ring Video Doorbell Pro 16v 30va Hardwired Door Chime Transformer
The links above are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.

Attempt 2: Honeywell Wired to Wireless Doorbell Kit

While searching for wireless solutions I came across some people using these two products from Honeywell.

Honeywell Home Wired to Wireless Doorbell Adapter Converter for Series 3, 5, 9 Honeywell Home Door Bells - RPWL4045A, White
Honeywell Home Wired to Wireless Doorbell Adapter Converter for Series 3, 5, 9 Honeywell Home Door Bells - RPWL4045A, White
Honeywell Home RDWL917AX2000/E Doorbell Portable Wireless Doorbell & Push Button-9 Series, Blue
Honeywell Home RDWL917AX2000/E Doorbell Portable Wireless Doorbell & Push Button-9 Series, Blue
The links above are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.

To get this working you have to wire your doorbell's power wires into the Doorbell Adapter then wirelessly link the adapter to the chime speaker. The installation and setup were pretty straight forward and you're able to upload any mp3 you want to the speaker via USB. However, for whatever reason, I found this setup to be very unreliable. Some of the issues I encountered over the couple weeks of using this setup ranged from:

  • No sound being played when the doorbell button is pressed
  • A very long delay between the doorbell button being pressed and the sound being played
  • The sound being played on repeat at random times during the day (and middle of the night) without the doorbell button being pressed

After a couple instances of having to get out of bed in the middle of the night to pull the batteries from the speaker I decided to return both products and go back to the drawing board.

Solution: Sonos + Home Assistant

At some point between returning the Honeywell devices and continuing my search on Google for another solution I was fiddling around in Home Assistant and had a realization that I may be able to pull this off with my current setup. After some more searching and tinkering I was able to get the UniFi doorbell chime to play through one of my Sonos speakers when the doorbell button was pressed. The following steps are specific to the UniFi Protect G4 Doorbell and a Sonos speaker but this theoretically could work with any doorbell/button and speaker that is connected to Home Assistant.

Steps

1. Get audio file to play

You can use any mp3 file you want. In my case, I wanted to use the chime that plays on the G4 doorbell when the button is pressed. Unfortunately Ubiquiti doesn't make these files publicly available. However they do allow you to upload your own chimes to the doorbell (community.ui.com + reddit.com/r/Ubiquiti). While I was poking around on the device I found all the default sound files, downloaded them to my computer, then uploaded them to a public repo on GitHub which you can find here.

Again, I chose to use the native chime from the doorbell to play in the house.

https://github.com/johnzanussi/unifi-g4-doorbell-sounds/blob/main/sounds/sounds_ring_button/Chime.wav

2. Install and configure integrations

Follow the directions for each of the Sonos and UniFi Protect integrations to get them configured in Home Assistant. I didn't run into any issues with either of these and I've been quite satisfied with their reliability.

3. Upload chime audio to Home Assistant

There's a couple ways to do this. The easiest way is to install the official File Editor add-on. Other options include SFTP and scp command.

  1. Install File Editor by following these instructions.

  2. Once installed, click the "File Editor" link in the left hand navigation.

Screenshot of the left hand navigation in Home Assistant with the File Editor link active
  1. Scroll down and select the www directory and then click the up arrow icon to bring up the "Upload File" modal.
Screenshot of the File Editor interface in Home Assistant with the Upload File icon active
  1. From there find the file on your computer to upload and upload it.

  2. Get the local URL for the file by concatenating the URL for your Home Assistant instance, local/, and the filename of the file you uploaded.
    In my case the URL parts look like this: http://192.168.20.121:8123/ + local/ + sounds_sounds_ring_button_Chime.mp3
    You can test that it works by loading it up into your browser.

4. Create automation

The following instructions are for creating a new automation in the visual editor. If you want to create the automation in code I've included automation in YAML format below.

In Home Assistant create a new Automation by logging in to your instance and clicking "Configuration" then "Automations". Once on the Automations page, click the "Add Automation" button in the bottom left then select "Start with an empty automation".

I named my automation Play chime on Sonos when doorbell is pressed.

Triggers

You'll need a single "Trigger" which is activated when the doorbell button is pressed. The values I've used are below. Simply, we're triggering the automation when the state of the doorbell is set to "on".

Trigger 1
FieldValue
Trigger TypeState
Entitybinary_sensor.doorbell_front_door
Toon
ModeSingle
screenshot-home-assistant-automation-triggers.png

Actions

UPDATE: Thanks to Reddit users u/Eriner_ and u/pie_faced_avitar for both suggesting to use the sonos.shapshot and sonos.restore services to pause and resume whatever may be playing when the doorbell chime is played.

Action 1

Create a snapshot of what is currently playing on all Sonos speakers.

FieldValue
Action TypeCall service
Servicesonos.snapshot
Entityall
With GroupChecked
Action 2

Set the volume of the speaker that is going to play the doorbell chime.

FieldValue
Action TypeCall service
Servicemedia_player.volume_set
Targetsmedia_player.living_room
Select the speaker from the Pick Entity button.
Level0.65
65%
Action 3

Play the doorbell chime on one or many Sonos speakers.

FieldValue
Action TypeCall service
Servicemedia_player.play_media
Targetsmedia_player.living_room
Select the same entity as above.
Content IDhttp://192.168.20.121:8123/local/sounds_sounds_ring_button_Chime.mp3
This is the URL we established by uploading the audio file in step 3.
Content Typemusic
Action 4

Wait 4 seconds (the length of the audio file) for the doorbell chime to play.

FieldValue
Action TypeDelay
hh mm ss ms00:00:04:000
Action 5

Restore all Sonos speakers back to what they were doing before chime was played.

FieldValue
Action TypeCall service
Servicesonos.restore
Entityall
With GroupChecked
screenshot-home-assistant-automation-triggers.png

As mentioned above here is the automation in YAML format.

alias: Play chime on Sonos when doorbell is pressed
description: ''
trigger:
- platform: state
entity_id: binary_sensor.doorbell_front_door
to: 'on'
condition: []
action:
- service: sonos.snapshot
data:
entity_id: all
- service: media_player.volume_set
target:
entity_id:
- media_player.living_room
data:
volume_level: 0.65
- service: media_player.play_media
target:
entity_id:
- media_player.living_room
data:
media_content_type: music
media_content_id: http://192.168.20.121:8123/local/sounds_sounds_ring_button_Chime.mp3
- delay:
hours: 0
minutes: 0
seconds: 4
milliseconds: 0
- service: sonos.restore
data:
entity_id: all
mode: single

5. Test and enjoy!

Save your automation then go test it out! Here's a quick video my wife and I recorded to showcase how responsive the automation is. There is a less than a second delay between the doorbell being pressed and the audio playing on the Sonos speaker in my house.

Overall I'm super happy with how this turned out as I didn't have to add anything new to my current setup and it leaves me with some flexibility for the future. If you have any questions feel free to shoot me an email at johnzanussi [at] gmail.com.