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

Здравствуйте. После обновления Home Assistant 2021.8.6 служба spotcast перестала работать.

Issue seems to be in the underlying package pychromecast or something server-side, but it is definitely not only happening with Spotcast:

hope some developper would fix it…

Hello everyone,

I’ve created a PR which should fix the timeout issue.

TLDR; Spotify changed the auth mechanism used in the casting process and that library which spotcast uses needed to be updated to match it accordingly.

3 Likes

@kylepotts thanks a lot! wait for it :wink: because user of HassOs, cant modify anything…and thanks for your reply on Github.

@fondberg “They complicate things a couple of times per year” …lol…so true…why make things simple when you can make them complicated…lovely world where we live…:wink:

wait for the fix!

Spotcast is the most used in my HA config…

1 Like

After holidays I wanted to reactivate my wake up spotcast script, but it doesn’t work anymore, no music (I hear the google home mini activation dong, but no music).

Error in the log:
Logger: homeassistant.core
Source: custom_components/spotcast/spotcast_controller.py:84
Integration: Spotcast ([documentation](https://github.com/fondberg/spotcast), [issues](https://github.com/fondberg/spotcast/issues))
First occurred: 18:15:32 (1 occurrences)
Last logged: 18:15:32

Error executing service: <ServiceCall spotcast.start (c:2f09aae5ccc5ede6a11bd77856644d02): random_song=True, shuffle=True, start_volume=15, entity_id=media_player.paire_cuisine, uri=spotify:playlist:37i9dQZF1E35HX5cTimjMT, ignore_fully_played=False, force_playback=False, offset=0, repeat=off>

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/core.py", line 1507, in catch_exceptions await coro_or_task File "/usr/src/homeassistant/homeassistant/core.py", line 1530, 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 143, in start_casting spotify_device_id = spotcast_controller.get_spotify_device_id( File "/config/custom_components/spotcast/spotcast_controller.py", line 202, in get_spotify_device_id spotify_cast_device.startSpotifyController(access_token, expires) File "/config/custom_components/spotcast/spotcast_controller.py", line 84, in startSpotifyController sp.launch_app() File "/usr/local/lib/python3.9/site-packages/pychromecast/controllers/spotify.py", line 87, in launch_app raise LaunchError( pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app

I tried updating sp_key & sp_dc (which were still valid for a few months), tried other uri’s, but nothing helps.
Same bug? Or can someone help (before school is back :-D)?

HI all

Does anyone know how long it usually takes for a PR to be adopted into HA OS?

I have 6 RFID readers around the house for choosing playlists which are all now all sitting idle as they don’t work until this is implemented is OS.

Seriously considering whether I now have to change to either supervised or docker so that I am able to implement the change myself.

Obviously I would prefer to save myself all that work if I can.

Thanks

I never been able to get spotcast to work. i’m not sure what I am doing, I am using spotify lovelace card. I hear my google home beep when i select it, but the music does not play and continues to play on my computer. this error log i am getting.

2021-08-21 10:05:37 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall spotcast.start (c:2d1e09ef6b9890ff71bab5baa600451f): device_name=Bedroom speaker, force_playback=True, account=default, shuffle=False, random_song=False, ignore_fully_played=False, repeat=off, start_volume=101, offset=0>
Traceback (most recent call last):
File "/snap/home-assistant-snap/334/lib/python3.8/site-packages/homeassistant/core.py", line 1507, in catch_exceptions
await coro_or_task
File "/snap/home-assistant-snap/334/lib/python3.8/site-packages/homeassistant/core.py", line 1530, in _execute_service
await self._hass.async_add_executor_job(handler.job.target, service_call)
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/var/snap/home-assistant-snap/334/custom_components/spotcast/__init__.py", line 143, in start_casting
spotify_device_id = spotcast_controller.get_spotify_device_id(
File "/var/snap/home-assistant-snap/334/custom_components/spotcast/spotcast_controller.py", line 202, in get_spotify_device_id
spotify_cast_device.startSpotifyController(access_token, expires)
File "/var/snap/home-assistant-snap/334/custom_components/spotcast/spotcast_controller.py", line 84, in startSpotifyController
sp.launch_app()
File "/snap/home-assistant-snap/334/lib/python3.8/site-packages/pychromecast/controllers/spotify.py", line 87, in launch_app
raise LaunchError(
pychromecast.error.LaunchError: Timeout when waiting for status response from Spotify app

Same with me. I’ve never gotten spotcast to work in my instance. I hear the beep tone on my Google devices but nothing ever plays. Major bummer…

Happy Sunday everyone.

Not sure if you have been following in the pr’s but the owner of the spotcast repo suggested we move the spotify controller out of the pychromecast library and into this integrations own repo in favor of fixing it in pychromecast.

I went ahead and did that in this pr New Spotify Controller and Auth Mechanism by kylepotts · Pull Request #244 · fondberg/spotcast · GitHub. Hopefully we can get this merged and approved.

In the meantime, if you want to try it yourself and you are familiar with git. You can checkout my branch https://github.com/kylepotts/spotcast/tree/kylep-spotify-new-cast-auth-method and try out the fix for yourself with the normal install mechanism of copying the files over to the custom_components/spotcast directory.

Thanks!

4 Likes

Kyle - I have just done this and can confirm that this now selects and plays the playlist on the correct speaker.

Thank you.

(I am not sure if it is relevant, but just before I copied your 3 files across, I had also created new sp_dc and sp-key codes.

I did this as I had freshly installed HA Supervisor (previously had been using HA OS) which I believe would have allowed me implement your initial fix - d’oh! - I should have just waited a couple of hours.

Anyway thank you for your work on this. Made my two teens very happy).

I also confirm playback start working again after simply copy/paste your files to custom components
I don’t need to renew sp_dc and sp_key

Glad to hear its working for you all :grinning:

2 Likes

thanks a lot @kylepotts !

just get this error now :

Update for sensor.playlists_sensor fails

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 446, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in async_device_update
    raise exc
  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/sensor.py", line 101, in update
    self._attributes["playlists"] = [{ "uri": x.uri, "name": x.name} for x in resp.items ]
TypeError: 'builtin_function_or_method' object is not iterable

but all seems to work fine…

same here
issue reported

Late to the party here but just started using Niklas spotcast component together with the Lovelace card and I’m quite blown away. Snyggt jobbat!

Question 1: is there a reason to migrate to Kyle’s fork if everything is working? Or do you foresee it will stop working?

Question 2: unrelated to spotcast maybe but is there any hack to cast without getting the notification sound when the speaker connects?

Thanks

My fork has been merged into the spotcast repo. There should be no reason to use my fork.

As for your second question, the speaker tone is actually part of the authentication process for cast devices I don’t think there is an easy way to turn it off.

1 Like

Coming here initially since I got issue with my spotcast same as everyone here. Thanks for the great community for fixings those things so fast! :slight_smile:

Regarding your question 2, you can actually remove the “cast notification sounds” from Google Home app and the settings of your chromecast. But it will disable it for all casts from all apps and not only from HA/Spotcast. I forgot if you can adjust the volume of that casting bip sound or not as well, maybe… :angel:

1 Like

thanks sounds cool, I couldn’t find the setting rn but I’ll check later after work

yeah i thought of making a script that lowers the volume, starts the cast and then raises the volume, but the volume-raise also has a sound… albeit a less annoying one, but would want it to be entirely silent ideally as I’m working on a setup that starts playing “spa-music” or like gregorian chanting and stuff as a gag when presence is detected in the bathroom

I’d really appreciate being able to mute the beep sound since I’m using spotcast mainly to start playlists for waking up and going to bed (nature sounds etc.). Would be great to fade in the wake up song same way as I fade in the lights meanwhile. Anyways, great job fixing the issue so fast!