Spotify in combination with chromecast

I am not sure how to do this part

I think I was able to find what triggers that.

I have a following script. It runs fine (in the configuration.yaml I have also defined the spotify media player including alias for the livingroom chromecast device)

spotify_test:
  alias: This Plays Spotify on Chromecast just fine
  sequence:
    - service: media_player.select_source
      data_template:
       entity_id: media_player.spotify
       source: livingroom
    - service: media_player.play_media
      data_template:
        entity_id: media_player.spotify
        media_content_type: playlist
        media_content_id: spotify:user:spotify:playlist:37i9dQZEVXcCFM9pYlRMzr

My real script has some templates, but I kept on this one just the bare minimum to make it work.

Now, I also use the chromecast devices to play internet radio. Again, this is the test script

spotify_ruin:
  alias: After I run tris script, previous script will stop working
  sequence:
    - service: media_player.play_media
      data_template:
        entity_id: media_player.living_room
        media_content_id: http://cdn.nrjaudio.fm/audio1/fr/30001/mp3_128.mp3?origine=fluxradios
        media_content_type: 'audio/mp4'

Now, when I run this script, it plays the internet radio fine as well. I stop it, but after that, the first script fails on calling the media_player.select_source service. I have tried all kind of things, from media_stop, turn_on, turn_off (the media_player.living_room), nothing helps.

Only after I go to spotify on my phone and select the living room from devices, then the script starts working again.

But it is not that the media_player.select_source service does not work, it does. After I have triggered teh livingroom device, I can then switch back to listening on the phone or different device. When I call the script, it will correctly swap to the living room. But each time I call media_player.play_media directly to the media_player.living_room, after that, the media_player.select_source (on media_player.spotify) fails with the following error:

Error executing service <ServiceCall media_player.select_source: entity_id=['media_player.spotify'], source=livingroom>

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/core.py", line 1010, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/__init__.py", line 403, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.6/asyncio/futures.py", line 332, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/media_player/spotify.py", line 241, in select_source
    self._player.transfer_playback(self._devices[source],
KeyError: 'livingroom'

Any idea?

Hi,

I have exactly the same problem?

I can easyily enough turn on your internet radio link.

Hwever i cannot turn on spotify playlists?

I basically have no knowledge about programming, so i do not know where or how to locate the problem. But i guess its something between the spotify and chromecast as you suggest??

I have the same problem. From what I have been able to figure out, selecting the chromecast as a source for spotify only works if the chromecast is currently playing spotify or has recently played it. After a while the connection between spotify and chromecast times out. It sounds like by running the internet radio script, it is cutting off the chromecasts connection with spotify. Spotify will not recognize the chromecast again until you open the app and connect to the chromecast.

I have not been able to find a workaround for this issue yet.

It works when I do that either from Spotify or from Google Assistant. I was thinking that if I can find a way to trigger an action by REST API in one of the services. Does not have to be complicated, once Spotify switches to the Chromecast devices, I can manage it from Home Assistant.
I have tried in Spotify API, but could not make that work.
And I did not find a way how to make Home Assistant to ask Google Assistant to do that.
Maybe someone here more experienced?

should be a way. WIth spotify connect it works well, with chromecast it does not

Aww just found out this does not work, so sad!

Anyone found a clever solution yet?

Same issue as other users.

I tried your script, but i always get this error:

Error executing service <ServiceCall media_player.select_source: entity_id=[‘media_player.spotify’], source=media_player.salotto_audio>
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1002, in _event_to_service_call
await service_handler.func(service_call)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/init.py”, line 403, in async_service_handler
yield from getattr(player, method[‘method’])(**params)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/spotify.py”, line 241, in select_source
self._player.transfer_playback(self._devices[source],
KeyError: ‘media_player.salotto_audio’

How to solve?

Hey all

Just wondering if anyone has solved this? It’s a shame I can’t trigger a spotify playlist to start playing when I get home from work.

Is there possibly a way we can trigger a Google Assistant command to start the playlist instead?

Yes there is a GA in this forum, not the broadcast but the command

So it turns out the command function can’t cast… so back to the drawing board unfortunately.

This is the setup I have been using as well for the last few months, and works really really well.

Does anyone happen to have working Docker images of Mopidy and/or Icecast that can be used for this?

Hi, the GitHub project is offline. Could you please update?

I don’t see an option to edit my original post. Here is the updated link: https://github.com/robwolff3/homeassistant-config/blob/master/packages/playlist.yaml

I’m experiencing the same problem. is there any solution?

I noticed that controlling spotify playlist from HA and using google home as audio output works only if google home is in “spotify mode reproduction”.
I’m not able to tell HA to say to Google Home to start a playlist.

Is this possible or not?

I have one cast-built-in Sony SRS-ZR7 sitting next to my Google Home.
I’ve turned to using tts.google_say on the Sony speaker telling Google Home to do stuff. LOL

3 Likes

I was wondering whether instead of the google_say, the Google Assistant SDK could be leveraged. Does anyone has install and knows whether scripts/REST API calls can be made to the addon?