Spotify in combination with chromecast

HI all, i am running into the following problem:

I want to play a spotifyplaylist to my chromecast. I did a clean install couple of days ago to the latest version. Had no troubles setting up spotify nor the chromecast however combining them isnt working.
I attempted to run this script:

speel:
  alias: 'Speel spotify'
  sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.Wouter
        media_content_id: 'spotify:user:spotify:playlist:37i9dQZF1DX153gOfbCM2i'
        media_content_type: playlist

My chromecast seems to react only showing a blue chromecast icon on a black background and nothing else, no sound.

In my log i found this:

17-05-06 11:09:01 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.spotify fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 225, in async_update_ha_state
    None, self.update)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/media_player/spotify.py", line 158, in update
    devices = self._player.devices().get('devices')
AttributeError: 'NoneType' object has no attribute 'get'

Is my script wrong? Am i missing dependencies? Did i set something up wrong?

Hopefully someone can help, thanks in advance!

Hi Wouser,

1st I use data_template instead of data and it works on my allplay speakers and Amazon echo.
2nd media_player.Wouter big letters are a problem
Try media_player.wouter instead.
3rd is media_player.wouter your chromecast or your player created from spotify
if it’s your chromecast try media_player.spotify instead.

Thanks for your reply!

Tried all suggestions, none worked unfortunately. media_player.Wouter works in an instance where i start radio so i guess it doesnt matter (although i tried lowercase aswell since u suggested it).

Also tried data_template without any change in the results. Also tried your third suggestion and it also got me curious. Mostly because i dont understand at what point it should know to play it on the chromecast?

The odd thing is that when i am already playing something from spotify on TV/phone/chromecast it works to change the playlist to the one in the script however it doenst initiate to play it on the chromecast when it isnt on yet…

Really hoping to get this working!

The media_player.spotify is an independent media player from your chromecast, as it represents spotify connect (like on your phone). So use media_player.spotify instead of wouter. You can chose the player either directly in the spotify media player in the frontend or by calling it in a script or
an automation like this to switch to the right source. (I just use the state of my Harmony remote normally.
Try this script works for me Just change the source, to what the name of your chromecast is in Spotify connect. I hope that helps! Cheers Mat

# Play random playlist and switch to Amazon Echo
script:  
  spotifydemo:
    alias: 'Spotify on echo'
    sequence:
      - service: media_player.select_source
        data:
          entity_id: media_player.spotify
          source: Mathias' Echo Dot
      - service: media_player.play_media
        data: 
          entity_id: media_player.spotify
          media_content_type: playlist
        data_template:
          media_content_id: >
            {%- set plists = ["spotify:user:spotify:playlist:37i9dQZF1DX55dNU0PWnO5", 
              "spotify:user:spotify:playlist:37i9dQZF1DWVyfHu8SNQgH",
              "spotify:user:spotify:playlist:37i9dQZF1DX9OTdoPfdJpF",
              "spotify:user:spotify:playlist:37i9dQZF1DX0N8QTiMHLoT",
              "spotify:user:spotify:playlist:37i9dQZF1DWZtZ8vUCzche",
               ] -%}
              {% set pindex =  (range(0, (plists | length - 1 ) )|random) -%}
              {{ plists[pindex] }}
2 Likes

Thanks again, i think im one step closer: I adjusted my script to resemble yours. The problem is probably not my script. When i check in the frontend the spotify component i cant selecht my chromecast as a source!
When i start it from my phone and tell spotify to play it on the chromecast in the frontend the source correctly shows it is playing on my chromecast and i can pause playing using both the chromecast component aswell as the spotify component.

Could the problem be that i cant correctly select the source because of some reason?

speel:
  alias: 'Speel spotify'
  sequence:
    - service: media_player.select_source
      data:
        entity_id: media_player.spotify
        source: Wouter
    - service: media_player.play_media
      data_template:
        entity_id: media_player.spotify
        media_content_id: 'spotify:user:spotify:playlist:37i9dQZF1DX153gOfbCM2i'
        media_content_type: playlist

Seems to be really a chromecast thing then.
your script nicely works for me just listening to System of a Down now :wink:
I read in another posting that someone had trouble with his amplifier not showing up as well.
Sorry I can’t be of further help then.

Hi

Did you solve that you can see your chromecast?

I can only see my PC and it is the same in Spotify.

Thanks

Hey!

Nope; couldnt find a way to fix this. As others stated i can play to my phone/PC but not my chromecasts…
Real big bummer to me and i hope someone knows how to fix this or have a workaround.

The problem is, at least from what i have been able to figure out, that the spotify player (connect implementation) in Home Assistant can’t “see” chromecast’s or Google Home’s unless you are already playing spotify from another source (say a android phone) on one of them.
This behavior is from what i can tell identical to the Spotify app on Windows.

So you can try to to run your script while you are playing music from spotify on your chrome cast and it should work. But if you ain’t the script will do nothing at all.

All in all; I think this is a problem from Spotify’s part and not Home Assistant

I can confirm that it does work when you are already playing on that particualr chromecast; then it is able to change playlists etc.

Is there anyway to fix this?

I had the same problem, it seems like the sourse selection is ignored completly, however there seem to be a possible fix coming with the next update.

https://community.home-assistant.io/t/spotify-ignoring-source

However I fear that the problem is more related to spotify connect, being a bit too dynamic, then the spotify component.

I don’t think this solves it sadly :confused:

Why dont you think this will solve it?

Any other hopes or solutions?

In short, if I understand this compnent correctly, it isn’t connected directly to Spotify, but rather tells a spotifyclient on a computer or phone what to do.

That spotify client provides a list of available devices to cast to and that list is the problem. Spotify only give home assistant access to the devices that are currently available, if thchromecast is turned of or connected to something else, it’s no longer available for home assistant.

Spotify has to solve this first as far as I can understand…

I don’t think that the component is interacting with spotify connect correctly. It simply deletes available sources at random when switching it seems.

I would recommend to try and play around with something like mobidy as an alternative. It seems a bit more complicated, but as far as I have understood it acts more like a dedicated player - nullefying the whole spotify connect debuggel. I will give it a try in the near future myself :slight_smile:

The component asks Spotify for a list of valid sources (devices) at a regular interval. It shows everything that Spotify says is available.

Thanks, just stumbled upon this and it made me understand how to select the source of a Spotify Connect device :slight_smile:

Your selection of a “random” playlist is also cool!

Interesting information!

It is working with my Phone and desktop when i leave the Spotify app/program on for a period of time.
Unfortunatly this isnt the case for my chromecasts. Hope there will be a way to solve this!

Hi,

When researching a possible solution, I stumbled upon this;


http://mkchromecast.com/

My thoughts are if we can install Spotify on a Pi we won’t be dependent on a computer or phone.
My knowledge of Raspbian and or linux are limited so I’m asking if you think this is feasible?

1 Like