UniFi Doorbell + Sonos: Speed and Reliability Boost

Hi all, I’m using a UniFi G4 Doorbell Pro and had an automation set up to play an MP3 file on my Sonos Play:1 speaker whenever someone pressed the ring button. Nothing fancy, but I always had a few issues that I’ve finally solved by (surprise!) actually reading the manual. :smile: I thought I’d share my upgraded automation in case it helps someone else as it seems all other post reference the method which causes the below issues:

Previous issues:

  • Noticeable delay between the button press and MP3 playback
  • binary_sensor.unifi_doorbell didn’t always trigger reliably
  • Random false triggers after camera or UniFi Console updates (e.g., at 2 a.m.)

The fix:
While reading the Home Assistant documentation for UniFi Protect, I noticed that the recommended approach is not to use the binary sensor, but instead to trigger the automation based on the UniFi Protect event and then filter for the event type "ring".

This method is not only faster, but also far more reliable and it ensures that only the actual “ring” event triggers the doorbell sound, eliminating those annoying false alarms.

Here is my automation YAML

alias: Türklingel
description: Automation that triggers when the G4 Doorbell Pro rings
triggers:
  - event_type: state_changed
    event_data:
      entity_id: event.haustur_turklingel
    trigger: event
conditions:
  - condition: template
    value_template: |
      {{ 'ring' in trigger.event.data.new_state.attributes.event_types }}
actions:
  - data:
      entity_id: media_player.kuche
    action: sonos.snapshot
  - action: media_player.media_stop
    metadata: {}
    data: {}
    target:
      device_id: 59d52a534aa141e19cb3356c0c8bad57
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.8
    target:
      device_id: 59d52a534aa141e19cb3356c0c8bad57
  - target:
      entity_id: media_player.kuche
    data:
      media_content_id: media-source://media_source/local/Chime.mp3
      media_content_type: audio/mpeg
    metadata:
      title: Chime.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
    action: media_player.play_media
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - data:
      entity_id: media_player.kuche
    action: sonos.restore
mode: single

Just for reference I used the below mp3 and File Editor add-on to upload it to /media/Chime.mp3

Chime.mp3

2 Likes

Thanks for the YAML, I have set this up and I get this error from my Sonos speaker… Error: Error calling SonosSpeaker.restore on Kitchen: HTTPConnectionPool(host=‘192.168.2.131’, port=1400): Read timed out. (read timeout=9.5)
Can you help at all?