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 %}