Spotify in combination with chromecast

Thanks @GigabitGuy for your input, I guess I’ll have to try Mopidy. Seems like a fun quiet sunday project.

I don’t want to dredge up an old thread but I doubt it’s possible to fix this without having some sort of hook into the Chromecast (a local phone/tablet) reason being is that they are competing standards! (Connect and cast) cast is built as a “2nd screen” whereas connect is more of a streaming client…

…that being said, I have just set up the Spotify component and will investigate (2 casts vs. 1 dot, I need the casts to work!)

Hi,

I can see only my Echo’s as available SOURCE, although I have chromecast audio, chromecast and Google Home.

WHat to do to make those appear in SOURCE?

I have added the following script:

  spotifyweeklyshuffle:
alias: 'Spotify Playlist Mix der Woche zufällig abspielen'
sequence:
  - service: media_player.shuffle_set
    data: 
      entity_id: media_player.spotify
      shuffle: 'true'
  - service: media_player.play_media
    data_template:
      entity_id: media_player.wohnung
      media_content_id: 'spotify:user:spotify:playlist:37i9dQZEVXcKMHncdFiqQ5'
      media_content_type: 'playlist'

but the only thing I can hear on my Google Home Mini is a short “bling” sound and then nothing happens. If I change the media_content_id to a mp4 stream and media_content_type to audio/mp4 it works as it should.
What is the problem with a Spotify playlist here?

Hey guys,

Am I correct in understanding that seeing a Chromecast Audio from the Spotify Connect component is difficult?
I am/was thinking of buying one.

You mean it works with general music, or will it play the playlist?

It works also with Spotify as long as you are or have played something to a speaker recently.
After some time it seems that the possible sources are not visible anymore.
I don’t know how to find out about the alias numbers.

@chimpy Don’t buy a chromecast if you want to use it with HA and the Spotify Component.
I must stress that this is not having to do with Chromecast being bad on the Spotify App, they are great. This is however an issue with the HA Spotify component forgetting (especialy) chromecasts rather quick (even when they are clearly visible in the Spotify App.

@Peleke It some time since I did this, and due to the above mentions issues I dont use it myself, but take a look at this, it should work (if your chromecast is remembered by the component) Spotify Playlist Player

1 Like

Thanks, I think the problem for me is about the bad memory of chromecast players…

Guessing there’s still no way around this? I’ve managed to get it working on my Google Home but only when I am already playing spotify to the device.

Asking Google Home to play a Spotify playlist on a Chromecast Audio works consistently for me, whether or not I’ve recently been playing on that particular Chromecast audio device (I have several).

But yeah, doesn’t work for me via Home Assistant’s Spotify component, even if I hardcode player names.

I wonder if the recently-announced Hass.io cloud functionality would allow for first-class Spotify player status finally? (My understanding it that Hassio’s limited ability to cast Spotify to Chromecasts is because it’s not really a player in its own right, so much as it controls existing players like your phone or computer. Or at least if it is a standalone player, it can’t see its own list of chromecast devices, only those discovered recently by your phone)

I figured out a way to accomplish casting Spotify Playlists to Chromecast Audio’s through Home Assistant. I use a writeup on Mopidy and Icecast2, can be found here: https://www.vittoriomonaco.de/home-automation-part-7.html and a Spotify Playlist Player frontend here: Spotify Playlist Player

You can use my adaptation here:
https://github.com/robwolff3/homeassistant-config/blob/master/packages/audiocontrol.yaml

From my testing so far it works pretty well.

1 Like

Mopidy, Iris, and Icecast look like an awesome combination. I’m gonna try this out and add Mopidy UI as a side panel to Home Assistant.

can you share this code? Thanks

Add an iframe component: https://home-assistant.io/components/panel_iframe/

how do you play from mopidy/icecast to chromecast in the panel_iframe?

Sorry, didn’t get that far with my implementation so I can’t tell you how to do it. What I would do is add the Mopidy web interface as an iFrame in Home Assistant, browse through Mopidy and select a song to play, then send the Icecast stream (which is a streaming mp3) currently playing to a 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??