Media browser, Spotify, select output device?

Here is a solution for you using the excellent SpotCast integration.

I added this on my dashboard

CastSelectorStudy

First install SpotCast using HACS.

I have four Chromecast Audio devices and a group called Flat. Each one has the room in the title (e.g. the Study cast entity is called media_player.study_audio_cast).

So I created an input_select drop-down list with the five human readable names and then wrote an automation to change to the correct casting device when changed in the drop-down list.

YAML from my dashboard

cards:
  - entity: media_player.spotify_john_tunnicliffe
    type: media-control
  - type: entities
    entities:
      - entity: input_select.chromecast_audio
      - entity: script.spotify_start
show_header_toggle: false
type: vertical-stack

YAML from my spotify.yaml file in my config/packages directory.

spotify: 
  client_id: !secret spotify_client_id
  client_secret: !secret spotify_client_secret

spotcast:
  sp_dc: !secret spotify_sp_dc
  sp_key: !secret spotify_sp_key
  
input_select:
  chromecast_audio:
    name: Chromecast Audio
    options:
      - "Study"
      - "Flat"
      - "Lounge"
      - "Kitchen"
      - "Bedroom"
    icon: mdi:cast-audio

automation:
- id: spotify_device_selected
  alias: 'Spotify: Device Selected'
  description: 'Starts music playing on the selected Chromecast Audio device'
  trigger:
  - platform: state
    entity_id: input_select.chromecast_audio
  condition: []
  action:
  - service: spotcast.start
    data:
      entity_id: >
        {% set selected_device = states('input_select.chromecast_audio').lower() %}
        {{ 'media_player.' + selected_device + '_audio_cast' }}      
      force_playback: true
  mode: single

script:
  # Spotify Start Playback
  spotify_start:
    alias: 'Spotify: Start Playback'
    sequence:
    - service: spotcast.start
      data:
        entity_id: "{% set selected_device = states('input_select.chromecast_audio').lower()\
          \ %} {{ 'media_player.' + selected_device + '_audio_cast' }}     \n"
        force_playback: true
    mode: single
    icon: mdi:spotify

Note: The Spotify Start Playback script solves the problem of when you have nothing playing, but the drop-down has the correct player selected.

15 Likes