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

After updating Spotcast to v3.5.10, I experience a delay of about 10 seconds between triggering the automation and start playing the music. Before, this was almost instant. Someone recognizes this?

1 Like

does multiple accounts works ?

i have the keys and following the instructions (spotcast & spotify)

spotcast 3.5.10
HA core-2021.5.5

but i cant get it to work

(default is orking fine)

I’m use spotcast shuffle true in a playlist 800 musics.
But, it always play a very similar sequence.
Does anyone knows how to do play completely different tracks sequence each script run?

My code:

      - service: spotcast.start
        data:
           device_name: Double Room Speaker
           uri: 'spotify:playlist:1OzvWussrGr2llMIcTazyP'
           shuffle: true

I tryed too:

sequence:
    - service: spotcast.start
      data:
         device_name: Bathroom Speaker
         uri: 'spotify:playlist:1OzvWussrGr2llMIcTazyP'
         shuffle: true
    - service: media_player.shuffle_set
      data:
        entity_id: media_player.spotify
        shuffle: true
    - wait_template: "{{ is_state('media_player.bathroom_speaker', 'playing') }}"
    - delay: '00:00:04'
    - service: media_player.media_next_track
      entity_id: media_player.spotify

Shuffle is for the next song. Not the first. Try random and shuffle

See the readme. There are examples

This must be caused by something else because the fallback to searching for cast devices in Spotcast is gone and that is the only thing that took time.

Turn on the debug logs. What I can guess is that the spotify app on the cast device is slow. Try another device

I was wrong. These are hard to support in spotcast as it is not a media_player. I thought you meant playback offset.

Guys, anyone seeing this error too:

Log Details (ERROR)

This error originated from a custom integration.

Logger: homeassistant.setup
Source: custom_components/spotcast/spotcast_controller.py:160
Integration: spotcast ([documentation](https://github.com/fondberg/spotcast), [issues](https://github.com/fondberg/spotcast/issues))
First occurred: 10:42:10 PM (1 occurrences)
Last logged: 10:42:10 PM

Error during setup of component spotcast

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 248, in _async_setup_component result = await task File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/spotcast/__init__.py", line 51, in setup spotcast_controller = SpotcastController(hass, sp_dc, sp_key, accounts) File "/config/custom_components/spotcast/spotcast_controller.py", line 160, in __init__ accounts["default"] = OrderedDict([("sp_dc", sp_dc), ("sp_key", sp_key)]) TypeError: 'NoneType' object does not support item assignment

Update to the latest version ( .13 , not any lower as the issue exists in .11 and .12 too)

1 Like

solved in the latest release

image

image

help, i cant get account freja and frede to work, - but the default (mine) is working fine

what am i doing wrong? when im using the default it shows me my chromecast devices image

OK thank you anyway for looking into it. :slight_smile:

Hey all. Got this component in and loading, i love it. But im stuck on how to make its output devices let me do playback on one (or more) of my Sonos at the same time. I dont see any of them showing up in the playback device list

1 Like

Read the README. Tldr; sonos os not supported

i am getting these errors now, what does it mean? mine spotify it still working

2021-07-26 08:57:23 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
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 "/config/custom_components/spotcast/helpers.py", line 60, in run
    return await loop.run_in_executor(executor, pfunc)
  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 78, in get_devices
    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

i think your sp_key and sp_dc are old

indeed, renewed and fixed

1 Like

Seems I’m having issues since updating to HA 2021.8.6 (container)

I checked the sp_dc & sp_key - both match from config to browser settings. Tried re-installing the integration - no luck. Any other suggestions? :thinking:

Error executing service: <ServiceCall spotcast.start ( *redacted - can include if necessary* ): uri=https://open.spotify.com/playlist/37i9dQZF1DX2Nc3B70tvx0?si=5d235b17288e4dab, random_song=True, shuffle=True, entity_id=media_player.google_home, ignore_fully_played=False, repeat=off, force_playback=False, start_volume=101, offset=0>
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
1 Like

After update Home Assistant - same here. Turning on/off players, reinstal addon, restart HA. This same problem

Suddenly seeing the same issue here:

2021-08-12 16:45:46 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] setting up with account t
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] expires: 1628782846 time: 1628779547.0107527
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] setting up with account t
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_spotify_devices: media_player.spotify_t: Spotify T: []
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_spotify_devices: {'devices': []}
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.woonkamer: Woonkamer cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='google-nest-hub-4660f5b8aabe10031a93ebd362367256-1._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.16', 8009))}, uuid='4660f5b8-aabe-1003-1a93-ebd362367256', _manufacturer='Google Inc.', model_name='Google Nest Hub', friendly_name='Woonkamer', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.soundbar: Soundbar cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='.xx.5-81704a75fd037a7c38090eb3c5dffea5._googlecast._tcp.local.')}, uuid='81704a75-fd03-7a7c-3809-0eb3c5dffea5', _manufacturer=None, model_name='.xx.5', friendly_name='Soundbar', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.slaapkamer: Slaapkamer cast info: ChromecastInfo(services={ServiceInfo(type='host', data=('192.168.xx.13', 8009)), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11-1._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11-2._googlecast._tcp.local.')}, uuid='0256c1dd-13b4-4c80-849b-281970d02d11', _manufacturer='Google Inc.', model_name='Google Home Mini', friendly_name='Slaapkamer', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.studeerkamer: Studeerkamer cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Home-d4063db0253e246c9d66d8f7fda77a6a-2._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.12', 8009)), ServiceInfo(type='mdns', data='Google-Home-d4063db0253e246c9d66d8f7fda77a6a._googlecast._tcp.local.')}, uuid='d4063db0-253e-246c-9d66-d8f7fda77a6a', _manufacturer='Google Inc.', model_name='Google Home', friendly_name='Studeerkamer', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.hele_huis: Hele huis cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Cast-Group-eec4b1d472ec428fad8f291a69a2d97d-1._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.12', 32059)), ServiceInfo(type='mdns', data='Google-Cast-Group-eec4b1d472ec428fad8f291a69a2d97d._googlecast._tcp.local.')}, uuid='eec4b1d4-72ec-428f-ad8f-291a69a2d97d', _manufacturer=None, model_name='Google Cast Group', friendly_name='Hele huis', is_audio_group=True, is_dynamic_group=False)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.boven: Boven cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Cast-Group-e18cddf284be43da9917ddb7d4ceb42c-1._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Cast-Group-e18cddf284be43da9917ddb7d4ceb42c._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.12', 32213))}, uuid='e18cddf2-84be-43da-9917-ddb7d4ceb42c', _manufacturer=None, model_name='Google Cast Group', friendly_name='Boven', is_audio_group=True, is_dynamic_group=False)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.zolder: Zolder cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Home-Mini-71d8c580bbd0166b72f10071a427b6cb-1._googlecast._tcp.local.'), ServiceInfo(type='host', data=('[::ffff:c0a8:5811]', 8009)), ServiceInfo(type='mdns', data='Google-Home-Mini-71d8c580bbd0166b72f10071a427b6cb._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.17', 8009)), ServiceInfo(type='mdns', data='Google-Home-Mini-71d8c580bbd0166b72f10071a427b6cb-2._googlecast._tcp.local.')}, uuid='71d8c580-bbd0-166b-72f1-0071a427b6cb', _manufacturer='Google Inc.', model_name='Google Home Mini', friendly_name='Zolder', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.tv_beneden: TV Beneden cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='TPM191E-bec0597.xx.b9a0a6966437ba87df4fe._googlecast._tcp.local.')}, uuid='bec05970.xx.b-9a0a-6966-437ba87df4fe', _manufacturer=None, model_name='TPM191E', friendly_name='TV Beneden', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.helpers] get_cast_devices: media_player.tv_slaapkamer: TV Slaapkamer cast info: ChromecastInfo(services={ServiceInfo(type='mdns', data='Chromecast-32e39183bc97abac51d77fce98a766a4._googlecast._tcp.local.')}, uuid='32e39183-bc97-abac-51d7-7fce98a766a4', _manufacturer=None, model_name='Chromecast', friendly_name='TV Slaapkamer', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] Chromecast devices: [ChromecastInfo(services={ServiceInfo(type='mdns', data='google-nest-hub-4660f5b8aabe10031a93ebd362367256-1._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.16', 8009))}, uuid='4660f5b8-aabe-1003-1a93-ebd362367256', _manufacturer='Google Inc.', model_name='Google Nest Hub', friendly_name='Woonkamer', is_audio_group=False, is_dynamic_group=None), ChromecastInfo(services={ServiceInfo(type='mdns', data='.xx.5-81704a75fd037a7c38090eb3c5dffea5._googlecast._tcp.local.')}, uuid='81704a75-fd03-7a7c-3809-0eb3c5dffea5', _manufacturer=None, model_name='.xx.5', friendly_name='Soundbar', is_audio_group=False, is_dynamic_group=None), ChromecastInfo(services={ServiceInfo(type='host', data=('192.168.xx.13', 8009)), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11-1._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11-2._googlecast._tcp.local.')}, uuid='0256c1dd-13b4-4c80-849b-281970d02d11', _manufacturer='Google Inc.', model_name='Google Home Mini', friendly_name='Slaapkamer', is_audio_group=False, is_dynamic_group=None), ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Home-d4063db0253e246c9d66d8f7fda77a6a-2._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.12', 8009)), ServiceInfo(type='mdns', data='Google-Home-d4063db0253e246c9d66d8f7fda77a6a._googlecast._tcp.local.')}, uuid='d4063db0-253e-246c-9d66-d8f7fda77a6a', _manufacturer='Google Inc.', model_name='Google Home', friendly_name='Studeerkamer', is_audio_group=False, is_dynamic_group=None), ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Cast-Group-eec4b1d472ec428fad8f291a69a2d97d-1._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.12', 32059)), ServiceInfo(type='mdns', data='Google-Cast-Group-eec4b1d472ec428fad8f291a69a2d97d._googlecast._tcp.local.')}, uuid='eec4b1d4-72ec-428f-ad8f-291a69a2d97d', _manufacturer=None, model_name='Google Cast Group', friendly_name='Hele huis', is_audio_group=True, is_dynamic_group=False), ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Cast-Group-e18cddf284be43da9917ddb7d4ceb42c-1._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Cast-Group-e18cddf284be43da9917ddb7d4ceb42c._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.12', 32213))}, uuid='e18cddf2-84be-43da-9917-ddb7d4ceb42c', _manufacturer=None, model_name='Google Cast Group', friendly_name='Boven', is_audio_group=True, is_dynamic_group=False), ChromecastInfo(services={ServiceInfo(type='mdns', data='Google-Home-Mini-71d8c580bbd0166b72f10071a427b6cb-1._googlecast._tcp.local.'), ServiceInfo(type='host', data=('[::ffff:c0a8:5811]', 8009)), ServiceInfo(type='mdns', data='Google-Home-Mini-71d8c580bbd0166b72f10071a427b6cb._googlecast._tcp.local.'), ServiceInfo(type='host', data=('192.168.xx.17', 8009)), ServiceInfo(type='mdns', data='Google-Home-Mini-71d8c580bbd0166b72f10071a427b6cb-2._googlecast._tcp.local.')}, uuid='71d8c580-bbd0-166b-72f1-0071a427b6cb', _manufacturer='Google Inc.', model_name='Google Home Mini', friendly_name='Zolder', is_audio_group=False, is_dynamic_group=None), ChromecastInfo(services={ServiceInfo(type='mdns', data='TPM191E-bec0597.xx.b9a0a6966437ba87df4fe._googlecast._tcp.local.')}, uuid='bec05970.xx.b-9a0a-6966-437ba87df4fe', _manufacturer=None, model_name='TPM191E', friendly_name='TV Beneden', is_audio_group=False, is_dynamic_group=None), ChromecastInfo(services={ServiceInfo(type='mdns', data='Chromecast-32e39183bc97abac51d77fce98a766a4._googlecast._tcp.local.')}, uuid='32e39183-bc97-abac-51d7-7fce98a766a4', _manufacturer=None, model_name='Chromecast', friendly_name='TV Slaapkamer', is_audio_group=False, is_dynamic_group=None)]
2021-08-12 16:45:47 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] cast info: ChromecastInfo(services={ServiceInfo(type='host', data=('192.168.xx.13', 8009)), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11-1._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11._googlecast._tcp.local.'), ServiceInfo(type='mdns', data='Google-Home-Mini-0256c1dd13b44c80849b281970d02d11-2._googlecast._tcp.local.')}, uuid='0256c1dd-13b4-4c80-849b-281970d02d11', _manufacturer='Google Inc.', model_name='Google Home Mini', friendly_name='Slaapkamer', is_audio_group=False, is_dynamic_group=None)
2021-08-12 16:45:50 DEBUG (SyncWorker_6) [custom_components.spotcast.spotcast_controller] Found cast device: Chromecast(None, port=8009, device=DeviceStatus(friendly_name='Slaapkamer', model_name='Google Home Mini', manufacturer='Google Inc.', uuid='0256c1dd-13b4-4c80-849b-281970d02d11', cast_type='audio'))
2021-08-12 16:46:04 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall spotcast.start (c:999e546c4febe44ced7365721538eaee): account=t, entity_id=media_player.slaapkamer, uri=spotify:track:5OoSxUZSbP1p7kb1d0SozG, offset=0, shuffle=False, start_volume=101, ignore_fully_played=False, repeat=off, random_song=False, force_playback=False>
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

Created a Github issue for it:

2 Likes