Spotcast - custom component to start playback on an idle chromecast device

Did you check the docs?

Hi, constantly getting an error when trying to call spotcast service:

Error for call_service at pos 1: Could not get spotify token

action:
- service: spotcast.start
data:
entity_id: media_player.hub
uri: spotify:playlist:blabla
random_song: true
mode: single

Official Integration is installed
Spotcast Installed

sd_dp and sd_key are correct

redirect uri is correct

I can start playing the playlist from lovelace media control card

type: media-control
entity: media_player.spotify_my_name

Tried everythink I can think of already. Also the Google Nest Hub becomes available to choose as a source only if I first start casting to it from Spotify web Player.

I cannot see spotify_device_id list in Logs using debug mode on spotcast

Thank you so much for your help if any.

1 Like

Dear all,

I saw many questions regarding the usage of Spotcast with Sonos speakers. As far as I understood, since Sonos is not compatible with chromecast I wonā€™t be able to play spotify on my Sonos speakers, correct ?

I already installed Spotcast and got the Sonos id from the debug mode but when starting the spotcast service I get an error message ā€œCould not find the device name xyzā€. In addition spotcast is not able to find any device.

Thank you for your answer, best regards

Hi everyone, I need help creating a second dashboard for a second account.

I added the second account via the Spotify integration. And also in the Configuration.Yaml adapted for Spotcast.

spotcast:
    sp_dc: XXXXXXXXXXXXXXXXXXXX
    sp_key: XXXXXXXXXXXXXXXXXXXXXXXXX
    accounts:
     sunnyk90:
        sp_dc: XXXXXXXXXXXXXXXXXXXXXXXXXX
        sp_key: XXXXXXXXXXXXXXXXXXXXXXXXX

Then I created a new dashboard to add SpotifyCards.

But even if I select the second account when creating the tile, my playlist is still selected and not the one from the second account.

Do I have to adjust something in the Configuration.yaml?

i just found this thread. is it possible to group multiple cast-capable devices and play on all using Spotcast?

Yeah, just create a group of speakers in your Google Home app and it will show up as separate media_player in Home Assistant. From there, you can use it with Spotcast.

https://support.google.com/googlenest/answer/7174267

1 Like

hi @Hmmbob thats the problem, my TV is cast ready but not being detected by google, so i need HA to deal with it. So re-phrasing the question. can i create a group of cast devices within HA and use it with spotcast?

Not sure, but try Media Player Group - Home Assistant

What you are trying to do has nothing to do with spotcast - spotcast just takes a cast media_player already available in HA.

1 Like

Ok thanks. Will Spotcast make use of Home Assistant Cast Groups? How does it detect the group. Maybe someone has an example

Hi @fondberg, a nice user finded a way to integrate spotcast with a notifier (this one if you are asking) so now if music is playing it is paused and then restored after tts messages (so cool!). I still have one little downsize : when music is from my wife account it is paused, but after the tts message my account is used (reducing waf factor).

Iā€™m not a programmer so Iā€™ve searched this answer before doing this post without any result: the account used is somehow ā€œexposedā€ and can ben ā€œsavedā€ and ā€œrestoredā€ as variable?

Thank you in advance

I think this is exactly what I need! If this the same for video over chromecasts?

What I want to create is a ā€œfollow meā€ function for whatever weā€™re watching on the family TV - so the film will duplicate onto the kitchen chromecast TV if one of us goes to make pudding etc, rather than having to pause till they get back.

Is all I need to do is just play to a group and itā€™ll automatically be there?

Iā€™d just go and try for myself, but Iā€™m still building the house, so trying to get my head round configurations before I buy my components - what I was thinking was HDMI splitter and hardwiring, but a networked solution is infinitely better.

Thanks for any light you can shedā€¦
cheers.

Iā€™ve searched around but canā€™t find this error anywhere in the forums.

Iā€™m getting the following when I try to play anything:

'ChromecastInfo' object has no attribute 'cast_type'

It was working previously so Iā€™m not sure if I missed some update info or have another issue.

Hey all, my cookies have just expired after 12 months and Iā€™m struggling to get new ones. Iā€™m following the process as per the docs (which I think is the same as a year ago) in Chrome developer tools but there is no sp_key and sp_dc cookie coming up. Anyone know if this process has changed? Thanks!

Youā€™re on 2021.12.0b0?

This has a pychromecast bump, which breaks the way Spotcast retrieves Cast devices.

Issue: Cannot load on beta 2021.12.0b.0 Ā· Issue #269 Ā· fondberg/spotcast Ā· GitHub
Probable fix: Fixes for 2021.12.0 by hmmbob Ā· Pull Request #271 Ā· fondberg/spotcast Ā· GitHub

Could you test if my fix fixes the issue for you?

Think this is no longer an open issue, right?

I think this is only working for music, but I did not try.

Hello, Iā€™m getting the error below and am not sure whatā€™s causing it. The automation seemed to work yesterday. Basically I press a button and it triggers a playlist coming on. But nothing happened this morning and the log below was produced. Any thoughts much appreciated! Thank you


This error originated from a custom integration.

Logger: homeassistant.components.automation.turn_j_sleep_playlist_on_in_night
Source: custom_components/spotcast/spotcast_controller.py:272 
Integration: Automation 
First occurred: 06:10:02 (16 occurrences) 
Last logged: 06:42:22

Turn J sleep playlist on in night: Error executing script. Unexpected error for call_service at pos 2: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=xxxxxx: Player command failed: Restriction violated, reason: UNKNOWN
While executing automation automation.turn_j_sleep_playlist_on_in_night
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://api.spotify.com/v1/me/player/play?device_id=xxxxxxx

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 371, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 571, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1534, in _execute_service
    await self._hass.async_add_executor_job(handler.job.target, service_call)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/spotcast/__init__.py", line 176, in start_casting
    spotcast_controller.play(
  File "/config/custom_components/spotcast/spotcast_controller.py", line 272, in play
    client.start_playback(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 1761, in start_playback
    return self._put(
  File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 306, in _put
    return self._internal_call("PUT", url, payload, kwargs)
  File "/usr/local/lib/python3.9/site-packages/spotipy/client.py", line 261, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 403, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=xxxxxxxx:
 Player command failed: Restriction violated, reason: UNKNOWN

Hi Hmmbob,

your fixes do fix the issue where the playlist keeps loading. Great job!
Whati understand is that the fix is related to how spotcast is looking for devices right?

Me and others in this threat have issue detecting the Sonos Device ID when the debug logs are enabled. Could it be related and maybe do you have any knowledge about how this can be fixed?

Itā€™s a fix on the way how Chromecast information from home assistant is parsed. It is, as far as I know, unrelated to how Spotcast retrieves Spotify devices.

Hi folks, Iā€™m using spotcast in a script to start playback to a specific Amazon Echo, using the Spotify device ID to target the device. The device ID times out occasionally though and spotcast throws an error related to not being able to find the device.

We get around it by issuing the ā€œSpotify Connectā€ voice command to Alexa with the Spotify app open, to refresh the device list in Spotify. Weā€™re doing it on a daily basis which isnā€™t the most convenient. Anyone have tips on how I could automate the refresh?