When I first got my UniFi G4 Doorbell, I originally set up Home Assistant to announce, "There is someone at the door," using Amazon Alexa. More recently, I have transitioned to playing a chime sound on Alexa when someone rings the doorbell. In this blog post, I outline how Home Assistant can be used to play sound files on Amazon Alexa and how text-to-speech (TTS) notifications can be used.

Prerequisites

With either of these approaches, the Alexa Media Player integration for Home Assistant is required.

Instructions on how to install Alexa Media Player can be found in the wiki for Alexa Media Player.

Amazon Alexa Text to Speech (TTS) with Home Assistant

Sending a text-to-speech notification to Alexa is done by calling the notify.alexa_media service with a data payload that contains the message and the Alexa devices that you want to play the announcement.

Here is a basic example where I announce, "There is someone at the door" across a number of our Alexa devices when someone runs the doorbell.

alias: Doorbell
description: Doorbell
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.g4_doorbell_doorbell
    from: "off"
    to: "on"
condition: []
action:
  - service: notify.alexa_media
    data:
      message: There is someone at the door
      target:
        - media_player.james_s_echo_plus_2
        - media_player.office_2
        - media_player.master_bedroom_2
        - media_player.kitchen_2
      data:
        type: announce
        method: all

Playing Sound Files with Amazon Alexa via Home Assistant

The notify.alexa_media service can also be used with a different data payload to play MP3 files. The MP3 files will need to be publicly hosted somewhere so that Alexa can play the file.

Where the file is hosted doesn't matter, provided it is publicly hosted. Because I use Home Assistant's Nabu Casa service to access my instance of Home Assistant remotely, this means I have a public URL for my Home Assistant, and I can leverage the fact that with Home Assistant, anything placed within the /config/www folder can be accessed by going to https://yourpublichomeassistanturl/local.

I have uploaded a ubiquiti_chime.mp3 file to an mp3s folder within /config/www which means that if I navigate to https://yourpublichomeassistanturl/local/mp3s/ubiquiti_chime.mp3 I can access the file.

I can now use the following action in an automation to play the chime MP3 file on our various Amazon Alexa devices:

  - service: notify.alexa_media
    data:
      message: >-
        <audio src='https://yourpublichomeassistanturl/local/mp3s/ubiquiti_chime.mp3'/>
      target:
        - media_player.james_s_ec
        ho_plus_2
        - media_player.office_2
        - media_player.master_bedroom_2
        - media_player.kitchen_2
      data:
        type: tts

The specifics of the message payload tells Amazon Alexa where to find the audio file that needs to be played.

Within the context of a wider automation, this would look as follows:

alias: "Doorbell"
description: "Doorbell"
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.g4_doorbell_doorbell
    from: "off"
    to: "on"
condition: []
action:
  - service: notify.alexa_media
    data:
      message: >
        <audio src='https://yourpublichomeassistanturl/local/mp3s/ubiquiti_chime.mp3'/>
      target:
        - media_player.james_s_echo_plus_2
        - media_player.office_2
        - media_player.master_bedroom_2
        - media_player.kitchen_2
      data:
        type: tts

Conclusion

The Alexa Media Player integration for Home Assistant allows you to issue an announcement using text-to-speech or audio files. There is also no reason why text-to-speech and audio files cannot be combined within a single automation by having multiple actions within the automation perform different calls to the notify.alexa_media service.