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

Anyone having this?
fondberg/spotcast - GitHub returned 502 for https://api.github.com/repos/fondberg/spotcast/branches/master

502 is a temporary server error at Github side - has nothing to do with spotcast.

FWIW: works fine here

This is the best thing since sliced bread.

My previous solution from 2017 was to host a virtualized android device which got triggered to actually press the cast button in the app using accessibility services and auto input. It was slow, used 4GB of RAM and not entirely reliable.

Iā€™m running OpenHAB but this stuff made me install HomeAssistant just so I can cast to an idle Spotify device!

Hi everybody,

I canā€™t get spotcast to work anymore. I uninstalled and reinstalled already but when I try to select a device, I always get:

Traceback (most recent call last):
  File "/config/custom_components/spotcast/spotcast_controller.py", line 142, in get_spotify_token
    self._access_token, self._token_expires = st.start_session(
  File "/usr/local/lib/python3.9/site-packages/spotify_token.py", line 18, in start_session
    response = session.get("https://open.spotify.com/get_access_token?reason=transport&productType=web_player",
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 677, in send
    history = [resp for resp in gen]
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 677, in <listcomp>
    history = [resp for resp in gen]
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 166, in resolve_redirects
    raise TooManyRedirects('Exceeded {} redirects.'.format(self.max_redirects), response=resp)
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1492, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1531, 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 145, in start_casting
    client = spotcast_controller.get_spotify_client(account)
  File "/config/custom_components/spotcast/spotcast_controller.py", line 176, in get_spotify_client
    return spotipy.Spotify(auth=self.get_token_instance(account).access_token)
  File "/config/custom_components/spotcast/spotcast_controller.py", line 136, in access_token
    self.ensure_token_valid()
  File "/config/custom_components/spotcast/spotcast_controller.py", line 132, in ensure_token_valid
    self.get_spotify_token()
  File "/config/custom_components/spotcast/spotcast_controller.py", line 148, in get_spotify_token
    raise HomeAssistantError("Could not get spotify token")
homeassistant.exceptions.HomeAssistantError: Could not get spotify token

Any recommendation?

Edit: Got it running again, my sp_dc and sp_key had changed

1 Like

If i listen to Spotify on one Google speaker and i start casting to an other google speaker, Spotify on the first speaker stops. I woud like to use spotcast to make some kind of multiroom systeem with buttons to add or stop the music on the selected speaker.

Anyone with an idea?

1 Like

Must be my problem. Spotify wont work with HA or Google Home, but I can cast with app.

1 Like

To do that you have to go into the Google Home App on your phone and create a speaker group. You can then group multiple chromecast devices together (my Android TV with integrated Chromecast can not be grouped, sadly - but all others I have work together).

You will then get an additional Chromecast device in your network, just like a regular Chromecast. I created multiple groups (upstairs, downstairs, all).

P.S.: In the Google Home App, there is also the option to set a delay for a device in the group. So if your AVR and your Chromecast Audio are not in sync (because your AVR applies Upmixing or whatever), you can correct it there.

2 Likes

Thanks, i know about the tv thing and i also already have a group with all my speakers. Itā€™s an option to make more combinations like bedroom and living room and bedroom and kitchenā€¦

Yeah I think there is no way to group them on the fly in HA.

If anybody knows one, please tell :slight_smile:

After installing the latest release of the integration (3.1.18) i am getting these errors:

2021-10-31 15:22:33 ERROR (SyncWorker_1) [custom_components.spotcast.helpers] spotify integration not found
2021-10-31 15:22:33 ERROR (SyncWorker_1) [custom_components.spotcast] Spotify integration was not found, aborting setup...
2021-10-31 15:22:33 ERROR (MainThread) [homeassistant.setup] Setup failed for spotcast: Integration failed to initialize.
2021-10-31 15:22:33 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform spotcast.sensor: Unable to set up component.

The spotify integration is installed properly as you can see in the attached screenshot:

Schermata 2021-10-31 alle 15.31.26

and reverting the the previuous release (3.1.17) the spotcaast integration is regularly loaded.
Hints?

Hmmm, 3.1.18 brought exactly the check that now fails, so it makes sense that returning to 3.1.17 helps.

Now it is a matter to find out why it fails for you :slight_smile:
@Darkfull-Dante Felix any idea?

edit: @maurizio53 any chance you can get a look into /.storage/core_entity_registry (best to download a copy locally first, as anything in .storage folder is danger zone for editing :wink: ) and see if you can find any line with "platform": "spotify",? My guess is that searching for media_player.mfabiani53 (your player name in the screenshot) will get you there :slight_smile:

I have the same issue. Sometimes reboote entire VM machine help

That would suggest a race condition where Spotcast set-up is faster than Spotify, but Spotcast does correctly list Spotify as a dependency in the manifest which should typically mean that Spotify is loaded before Spotcast, according to dev docs. :thinking:

I found it, but with ā€œmedia_player.spotify_mfabiani53ā€ as nameā€¦

1 Like

Yes, i think soā€¦

Great - how does it look like? Can you copy-paste it here?

(Just that section)

Here it isā€¦

            {
                "entity_id": "media_player.spotify_mfabiani53",
                "config_entry_id": "xxxxxxxxxxxxxxxxxxxxxxx",
                "device_id": "xxxxxxxxxxxxxxxxxxxxx",
                "area_id": null,
                "unique_id": "mfabiani53",
                "platform": "spotify",
                "name": null,
                "icon": null,
                "disabled_by": null,
                "capabilities": {},
                "supported_features": 0,
                "device_class": null,
                "unit_of_measurement": null,
                "original_name": "Spotify mfabiani53",
                "original_icon": "mdi:spotify"
            },
1 Like

Yeah, that looks about right. No idea whatā€™s happeningā€¦
Maybe best to raise an issue @ Github: https://github.com/fondberg/spotcast

Maybe itā€™s better if you do it for meā€¦ I am not so good in these things and my English is really poorā€¦ I will appreciate itā€¦

Could you please share some yaml as to how to launch Spotify programmatically (such as in an automation) on an Amazon Echo device ? Thank you !

1 Like