Calling Alexa routines from Home Assistant

I have been trying to find a simple way to have Home Assistant start and stop the internet radio station Radio Paradise on all my Alexa speakers in the house. I have a couple of Echo dots and Echo Flex hooked up to various speakers around the house and I wanted to be able to trigger playing from Home Assistant. I was using Google for this, but there is not much innovation happening with Google Assistant and it is just too chatty with feedback. Alexa is more flexible and can have a quiet ding when it does a command.

I have not used Scripts in Home Assistant, so I needed something simple to start with. I was investigating running the ChromeCast script by Bob_NL (Bob Visser) and adapting it to Alexa, but it was not working. I tried hacking a few scripts, but I was having no success. I did learn a lot from all my failures, but no success. I then started to see if I could trigger something from Home Assistant and came across a newer feature in the custom component Alexa Media Player , trigger a Routine. There was only a bit of documentation on this, but I was able to cobble together a quick script from the new knowledge I gained from my hacking 🙂

{ "entity_id": "media_player.alexa", 
"media_content_id": "Goodnight",
"media_content_type": "routine"
}

First I created 2 routines in the Alexa app ‘Radio Paradise’ and ‘Stop playing music’ The key for Radio Paradise is to select Music @ Media and then add ‘on All Speakers ‘to the end of the command.

Add Action, Music, Play Radio Paradise on all Speakers, From TuneIn.

The Stop Music is straightforward and I just used the built in commands for it. Add Action, Device Settings, Stop Audio.

Once this was set I was able to start getting these triggered from Home Assistant via a Script.

radioparadise:
alias: Play Radio Paradise
icon: "mdi:play"
sequence:
- service: media_player.play_media
data:
media_content_id: Radio Paradise
media_content_type: routine
entity_id: media_player.den_echo_dot
mode: single

stopmusic:
alias: Stop playing music on Alexa
icon: "mdi:stop"
sequence:
- service: media_player.play_media
data:
media_content_id: stop playing music
media_content_type: routine
entity_id: media_player.den_echo_dot
mode: single

Next is to add the following to the customize.yaml. Remember that this needs a special include in your configuration.yaml

homeassistant:
customize: !include customize.yaml
packages: !include_dir_named packages # package setup

Add this to customize.yaml

script.radioparadise:
friendly_name: Start Playing
icon: mdi:play
script.stopmusic:
friendly_name: Stop Playing
icon: mdi:stop

Next was to create a Lovelace card with the following code after you restart Home Assistant to make sure all is good:

entities:
- action_name: Play
entity: script.radioparadise
- action_name: Stop
entity: script.stopmusic
show_header_toggle: false
title: Radio Paradise
type: entities

This is a good start and as always it good to build on a win. I will definitely be expanding on this as I centralize all my things with Home Assistant.

btw: here is a link to my Github repo for my Home Assistant config files.

Leave a Reply

Your email address will not be published. Required fields are marked *