Spotify routing by voice (Alexa)

Just to amuse myself. I can now say:
Alexa, tell DeeDee (the name of my HA instance) to send Spotify upstairs
Alexa, tell DeeDee to send Spotify downstairs

Add to your intent schema’s intents array:

      {
      "slots": [
        {
          "name": "SpotifyLocation",
          "type": "SpotifyLocations"
        }
      ],
      "intent": "SendSpotifyIntent"
    }

Define some slot values. Type: SpotifyLocations, values: upstairs / downstairs (or whatever)

Add to Alexa config YAML:

SendSpotifyIntent:
  action: 
    - service: media_player.select_source
      entity_id: media_player.spotify
      data_template:
        source: >
          {%- set location = SpotifyLocation.lower() -%}
          {%- if location == "upstairs" %}Master bedroom Echo Dot
          {%- elif location == "downstairs" -%}Livingroom Echo
          {%- endif %}
  speech:
    type: plaintext
    text: Sending music {{SpotifyLocation}}
```
Extend that source template else/if to meet your needs. Check the states dev tool for the correct source names.

This'd be cool to tie to occupancy and have music follow you automatically rather than via Alexa.
2 Likes

Hello,
Related question but not directly.
How do you setup the echo devices in HA so they can be differentiated? Is that a new capability?
Last time I checked there was no unique device id coming from alexa intents.

This is using the Spotify platform. It’s a variety of media_player. Spotify can send output to any device that you’ve ever used Spotify Connect with.

Hi! :slight_smile:
Speaking of the Spotify platform. I have a bunch of cast devices like google home and chromecast audio and I’ve been trying out some automations but there is a problem. If I cast from my phone to google home for example, it shows up in source_list for my media_player.spotify entity but pretty soon after I play on another device or stop playing the cast device is removed from source_list making automations unusable since there are no valid source to select for media_player.select_source… Am I missing something here?

I noticed this too. I think this is a problem with the Google devices. They don’t broadcast that they’re available as a Spotify Connect device unless they’re actively playing. I think this is something that Google needs to fix.

On the other hand, I have an Amazon FireTV and it’s always available as a Spotify Connect device.

Any resolution to getting Google devices to stay available as a Spotify Connect entry? One thing I need!