Play Spotify (and radio stations) to chromecast from HA

A workaround for those wanting to play spotify to chromecasts from home assistant.

I cant use the official spotify component with chromecast, because it keeps forgetting sources

This requires that you can run a squeezebox server on some computer on your network!

Install logitech media server from here: Logitech Media Server Downloads

Go to server settings and install plugins:

Spotty, for spotify
Chromecast bridge, this allows you to use a chromecast as a squeezebox

now the code for HA:

There is a speaker selector, radiostation selector, and playlistselector based on BobNL’s code, and som buttons for control. And i have include code for album art based on which player is active.Should look like this when you’re done:

configuration.yaml:

media_player:
  - platform: squeezebox
    host: 192.168.0.xx
    port: 9000    
# playlist selector   
input_select:
  playliste:
    name: 'Playliste:'
    options:
      - Højt humør
      - Songs to sing in the car
      - Jokkes liste
      - Julesange du kender
      - Weekendhygge
      - Rock du kender
      - Liv og glde dage
      - Cecilie
      
 #speaker selector   
  speaker:
    name: 'Højtaler:'
    options:
      - Køkken
      - Spisestue
      - Gruppe
    initial: Gruppe
    icon: mdi:speaker-wireless
#radiostation selector  
  radio:
    name: 'Radio station:'
    options:
      - P3
      - Nova
      - VLR
      - Skala
      - Popfm
      - TheVoice 
#volume control      
input_number: 
  volume_radio:
    name: Volume
    icon: mdi:volume-high
    min: 0
    max: 1
    step: 0.05
#album art for dashboard    
camera:
  - platform: generic
    still_image_url: "{{states('sensor.lrtoomuch')}}"

automations.yaml:

- alias: Set Radio Volume
  trigger:
    platform: state
    entity_id: input_number.volume_radio
  action:
    service: media_player.volume_set
    data_template:
      entity_id: '{% if is_state("input_select.speaker", "Køkken") %} media_player.kkkenet
        {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio
        {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_3
        {% endif %}'
      volume_level: '{{  states.input_number.volume_radio.state  }}' 

sensors.yaml:

  - platform: template
    sensors:
### volume kontrol##########################################################################################
      kkken_vol:
        value_template:
          "{{ states.media_player.kkkenet.attributes.volume_level }}" 
      radio_vol:
        value_template:
          "{{ states.media_player.radio.attributes.volume_level }}"   
      gruppe_vol:
        value_template:
          "{{ states.media_player.gruppe_3.attributes.volume_level }}"           
      lrtest:
        value_template: >
          {% if is_state('media_player.kkkenet', 'playing') %}
            kkkenet
          {% elif is_state('media_player.radio', 'playing') %}
            radio
          {% elif is_state('media_player.gruppe_3', 'playing') %}
            gruppe
          {% else %}
            Off            
          {% endif %}
      lrtoomuch:
        friendly_name: "Radio URL"
        value_template: >-
          {% if is_state('sensor.lrtest', 'gruppe') %}
            http://192.168.0.30:8123/api/media_player_proxy/media_player.gruppe_3?api_password=jokke  
          {% elif is_state('sensor.lrtest', 'kkkenet') %}
            http://192.168.0.30:8123/api/media_player_proxy/media_player.kkkenet?api_password=jokke  
          {% elif is_state('sensor.lrtest', 'radio') %}
            http://192.168.0.30:8123/api/media_player_proxy/media_player.radio?api_password=jokke 
          {% elif is_state('sensor.lrtest', 'Off') %}
            https://media.idownloadblog.com/wp-content/uploads/2018/03/Apple-Music-icon-002.jpg            
          {% endif %}

groups.yaml

  spotifyradio:
   name: Spotify
   entities:
   - input_select.speaker
   - input_select.playliste
   - input_select.radio
   - script.radio   
   - script.spotify1
   - input_number.volume_radio
   - script.fremad
   - script.playpause
   - script.tilbage
   - camera.generic_camera

scripts.yaml:

#script til spotify afspilning
  spotify1:
     alias: Spil Spotify
     sequence:  
       -  service: media_player.squeezebox_call_method
          data_template:
            entity_id: media_player.kkken2
            command: playlist
            parameters: ["shuffle","1"]
       -  service: media_player.squeezebox_call_method
          data_template:
            entity_id: media_player.radio
            command: playlist
            parameters: ["shuffle","1"]
       -  service: media_player.squeezebox_call_method
          data_template:
            entity_id: media_player.gruppe_2
            command: playlist
            parameters: ["shuffle","1"]         
       -  service: media_player.play_media
          data_template:
            entity_id: >
             {% if is_state("input_select.speaker", "Køkken") %} media_player.kkken2
             {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
             {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
             {% endif %}
            media_content_id: >
             {% if is_state("input_select.playliste", "Højt humør") %} spotify:user:spotify:playlist:37i9dQZF1DX5SrqpuffRKXb
             {% elif is_state("input_select.playliste", "Songs to sing in the car") %} spotify:user:spotify:playlist:37i9dQZF1DWWMOmoXKqHTD
             {% elif is_state("input_select.playliste", "Jokkes liste") %} spotify:user:xl9buzfaaeqix84aonkozefmx:playlist:3DFHpFkEk9H0BDZmAPc4HF
             {% elif is_state("input_select.playliste", "Julesange du kender") %} spotify:user:spotify:playlist:37i9dQZF1DXbLJ4V4LNcKE 
             {% elif is_state("input_select.playliste", "Weekendhygge") %} spotify:user:spotify:playlist:37i9dQZF1DWZdL27osEgj6
             {% elif is_state("input_select.playliste", "Rock du kender") %} spotify:user:spotify:playlist:37i9dQZF1DXcSNirXzsHRX
             {% elif is_state("input_select.playliste", "Liv og glde dage") %} spotify:user:spotify:playlist:37i9dQZF1DWW4SalrrfPEU
             {% elif is_state("input_select.playliste", "Cecilie") %} spotify:user:spotify:playlist:5ExZRQHiYCO6jqL9JzhMHQ
             {% endif %}
            media_content_type: playlist             
#script til radio afspilning            
  radio:
     alias: Spil Radio
     sequence:
       -  service: media_player.play_media     
          data_template:
            entity_id: >
             {% if is_state("input_select.speaker", "Køkken") %} media_player.kkken2
             {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
             {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
             {% endif %}
            media_content_id: >
             {% if is_state("input_select.radio", "P3") %} http://live-icy.gss.dr.dk:8000/A/A05H.mp3
             {% elif is_state("input_select.radio", "Nova") %} http://195.184.101.204/nova128
             {% elif is_state("input_select.radio", "VLR") %} http://streaming.fynskemedier.dk:80/vlr
             {% elif is_state("input_select.radio", "Popfm") %} http://195.184.101.202/pop128
             {% elif is_state("input_select.radio", "TheVoice") %} http://195.184.101.203/voice128
             {% elif is_state("input_select.radio", "Skala") %} http://webradio.skala.fm:80/aabenraa
             {% endif %}
            media_content_type: MUSIC       
#styreknapper til musik og radio            
  playpause:
     alias: playpause
     sequence:
       - service: media_player.media_play_pause   
         data_template:
            entity_id: >
             {% if is_state("input_select.speaker", "Køkken") %} media_player.kkken2
             {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
             {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
             {% endif %}     
  fremad:
     alias: fremad
     sequence:
       - service: media_player.media_next_track
         data_template:     
            entity_id: >
             {% if is_state("input_select.speaker", "Køkken") %} media_player.kkken2
             {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
             {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
             {% endif %} 
  tilbage:
     alias: tilbage
     sequence:
       - service: media_player.media_previous_track
         data_template:     
            entity_id: >
             {% if is_state("input_select.speaker", "Køkken") %} media_player.kkken2
             {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
             {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
             {% endif %}
2 Likes

Hey i looks great but i cant get it to work the 2nd box

# playlist selector   
input_select:
  playliste:
    name: 'Playliste:'
    options:
      - Højt humør
      - Songs to sing in the car
      - Jokkes liste
      - Julesange du kender
      - Weekendhygge
      - Rock du kender
      - Liv og glde dage
      - Cecilie
      
 #speaker selector   
  speaker:
    name: 'Højtaler:'
    options:
      - Køkken
      - Spisestue
      - Gruppe
    initial: Gruppe
    icon: mdi:speaker-wireless
#radiostation selector  
  radio:
    name: 'Radio station:'
    options:
      - P3
      - Nova
      - VLR
      - Skala
      - Popfm
      - TheVoice 
#volume control      
input_number: 
  volume_radio:
    name: Volume
    icon: mdi:volume-high
    min: 0
    max: 1
    step: 0.05
#album art for dashboard    
camera:
  - platform: generic
    still_image_url: "{{states('sensor.lrtoomuch')}}"

There sould i but it in the configuration.yaml its not alowed in the form it is there.

You need to remove the second “input_number:” line. You can only have one of those.

i have direct copiede it from yours eks.
it is the first input_select: that is the problem, is it ass. with the media player? since it is in 2 differet boxes.

This is copied directly from my configuration.yaml.

input_select:
  playliste:
    name: 'Playliste:'
    options:
      - Højt humør
      - Songs to sing in the car
      - Jokkes liste
      - Julesange du kender
      - Nye julesange
      - Christmas hits
      - Dansk jul
      - Julefrokosten
      - Weekendhygge
      - Rock du kender
      - Liv og glde dage
      - Cecilie
      
 #højtaler vælger     
  speaker:
    name: 'Højtaler:'
    options:
      - Køkken
      - Spisestue
      - Gruppe
    initial: Gruppe
    icon: mdi:speaker-wireless
#radiostation vælger    
  radio:
    name: 'Radio station:'
    options:
      - P3
      - Nova
      - VLR
      - Skala
      - Popfm
      - TheVoice 
#volume kontrol      
input_number: 
  volume_radio:
    name: Volume
    icon: mdi:volume-high
    min: 0
    max: 1
    step: 0.05

Sorry, my bad. For some reason I saw the input_number as another input_select. Nevermind me…

        media_player:
      - platform: squeezebox
        host: 10.0.0.25
        port: 9000
        
    #playlist selector   
    input_select:
      playliste:
        name: 'Playliste:'
        options:
          - Megadea
          - Rock Party
          - 80er Fest
          - Rock klassikere
          - Old School Metal
          
     #speaker selector   
      speaker:
        name: 'Højtaler:'
        options:
          - Sove Cast
          - Spisestue
          - Gruppe
        initial: Gruppe
        icon: mdi:speaker-wireless
    #radiostation selector  
      radio:
        name: 'Radio station:'
        options:
          - P3
          - Nova
          - VLR
          - Skala
          - Popfm
          - TheVoice 
    #volume control      
    input_number: 
      volume_radio:
        name: Volume
        icon: mdi:volume-high
        min: 0
        max: 1
        step: 0.05
    #album art for dashboard    
    camera:
      - platform: generic
        still_image_url: "{{states('sensor.lrtoomuch')}}"
        
    automation:
      - alias: Set Radio Volume
        trigger:
        platform: state
        entity_id: input_number.volume_radio
        action:
        service: media_player.volume_set
        data_template:
          entity_id: '{% if is_state("input_select.speaker", "Sove Cast") %} media_player.sovevrelse
            {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio
            {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_3
            {% endif %}'
          volume_level: '{{  states.input_number.volume_radio.state  }}'


      - platform: template
        sensors:
    ### volume kontrol##########################################################################################
      sovecast_vol:
        value_template:
          "{{ states.media_player.sovevrelse.attributes.volume_level }}" 
      radio_vol:
        value_template:
          "{{ states.media_player.radio.attributes.volume_level }}"   
      gruppe_vol:
        value_template:
          "{{ states.media_player.gruppe_3.attributes.volume_level }}"           
      lrtest:
        value_template: >
          {% if is_state('media_player.sovevrelse', 'playing') %}
            sovecast
          {% elif is_state('media_player.radio', 'playing') %}
            radio
          {% elif is_state('media_player.gruppe_3', 'playing') %}
            gruppe
          {% else %}
            Off            
          {% endif %}
      lrtoomuch:
        friendly_name: "Radio URL"
        value_template: >-
          {% if is_state('sensor.lrtest', 'gruppe') %}
            http://myip:8123/api/media_player_proxy/media_player.gruppe_3?api_password=T3cT3c  
          {% elif is_state('sensor.lrtest', 'sovecast) %}
            http://myip:8123/api/media_player_proxy/media_player.sovevrelse?api_password=T3cT3c  
          {% elif is_state('sensor.lrtest', 'radio') %}
            http://myip:8123/api/media_player_proxy/media_player.radio?api_password=T3cT3c 
          {% elif is_state('sensor.lrtest', 'Off') %}
            https://media.idownloadblog.com/wp-content/uploads/2018/03/Apple-Music-icon-002.jpg            
          {% endif %}
          
    group:
      spotifyradio:
        name: Spotify
        entities:
          - input_select.speaker
          - input_select.playliste
          - input_select.radio
          - script.radio   
          - script.spotify1
          - input_number.volume_radio
          - script.fremad
          - script.playpause
          - script.tilbage
          - camera.generic_camera
       
    script:
    #script til spotify afspilning
      spotify1:
         alias: Spil Spotify
         sequence:  
           -  service: media_player.squeezebox_call_method
              data_template:
                entity_id: media_player.sovecast2
                command: playlist
                parameters: ["shuffle","1"]
           -  service: media_player.squeezebox_call_method
              data_template:
                entity_id: media_player.radio
                command: playlist
                parameters: ["shuffle","1"]
           -  service: media_player.squeezebox_call_method
              data_template:
                entity_id: media_player.gruppe_2
                command: playlist
                parameters: ["shuffle","1"]         
           -  service: media_player.play_media
              data_template:
                entity_id: >
                 {% if is_state("input_select.speaker", "Sove Cast") %} media_player.sovevrelse2
                 {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
                 {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
                 {% endif %}
                media_content_id: >
                 {% if is_state("input_select.playlist", "Megadea") %} spotify:user:21bz4tmwxagbnlt5zblz4wjiy:playlist:25S49JQP1NhwI4FtbKHMST
                 {% elif is_state("input_select.playlist", "Rock Party") %} spotify:user:spotify:playlist:37i9dQZF1DX8FwnYE6PRvL
                 {% elif is_state("input_select.playlist", "80er Fest") %} spotify:user:spotify:playlist:37i9dQZF1DWVvS1ouVmdXl
                 {% elif is_state("input_select.playlist", "Rock klassikere") %} spotify:user:spotify:playlist:37i9dQZF1DWXDeqyKSbZXz
                 {% elif is_state("input_select.playlist", "Old School Metal") %} spotify:user:spotify:playlist:37i9dQZF1DX2LTcinqsO68
                 {% endif %}
                media_content_type: playlist             
    #script til radio afspilning            
      radio:
         alias: Spil Radio
         sequence:
           -  service: media_player.play_media     
              data_template:
                entity_id: >
                 {% if is_state("input_select.speaker", "Sove Cast") %} media_player.sovevrelse2
                 {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
                 {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
                 {% endif %}
                media_content_id: >
                 {% if is_state("input_select.radio", "P3") %} link to P#
                 {% elif is_state("input_select.radio", "Nova") %} link to Nova
                 {% elif is_state("input_select.radio", "VLR") %} link to VLR
                 {% elif is_state("input_select.radio", "Popfm") %} link to Popfm
                 {% elif is_state("input_select.radio", "TheVoice") %} link to The Voice
                 {% elif is_state("input_select.radio", "Skala") %} link to Skala
                 {% endif %}
                media_content_type: MUSIC       
    #styreknapper til musik og radio            
      playpause:
         alias: playpause
         sequence:
           - service: media_player.media_play_pause   
             data_template:
                entity_id: >
                 {% if is_state("input_select.speaker", "Sove Cast") %} media_player.sovevrelse2
                 {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
                 {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
                 {% endif %}     
      fremad:
         alias: fremad
         sequence:
           - service: media_player.media_next_track
             data_template:     
                entity_id: >
                 {% if is_state("input_select.speaker", "Sove Cast") %} media_player.sovevrelse2
                 {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
                 {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
                 {% endif %} 
      tilbage:
         alias: tilbage
         sequence:
           - service: media_player.media_previous_track
             data_template:     
                entity_id: >
                 {% if is_state("input_select.speaker", "Sove Cast") %} media_player.sovevrelse2
                 {% elif is_state("input_select.speaker", "Spisestue") %} media_player.radio_2
                 {% elif is_state("input_select.speaker", "Gruppe") %} media_player.gruppe_4
                 {% endif %}

I can’t this to work, I’m using packed mode and all is in one yaml file.
Please help, I have replaced the links with text, only 2 urls are allowed as a new member in the Reply.
Last error is:
Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->platform. (See /config/configuration.yaml, line 103).

What exactly does this do?
Not working for me.

It should play radio and spotify playlists in HA

Hello,

Is this method still working for you?

Thanks!