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

Odly enough, that helped! Thanks!

This is the wrong forum…

Having this error today.
Failed to call service spotcast/start. get_spotify_token() got an unexpected keyword argument ‘sp_dc’

I did recheck my sp_dc and sp_key.
restarted HA.
Uninstalled spotcast. restarted HA. and reinstalled. No luck

I have the same problem

Maybe the cookies that generated the keys have been invalidated / expired? My spotcast component continues to work fine. Try regenerating new keys in incognito and update config.

No, this has to do with the 3.2.0 update. You most likely are still running the older version which does work properly. https://github.com/fondberg/spotcast/issues/104

Should be fixed soon, but in the meantime I downgraded back.

Problem solved with update 3.2.1

Thanks!
@fondberg

I’m still having my other problem.

Whenever I choose a speaker to play it on, it always plays my first playlist and I can’t seem to be able to change playlist… It always plays the first playlist and I can’t change it.

I’m I missing something somewhere?

Thanks in advance!

That seems like a spotify card problem. Ask the q over there so ppl there can help

Hi @fondberg - first of all let me say - awesome work man !!!

I have an issue which I cannot understand (it may be a minor slip) - after installing from HACS the spotcast, configuring it with the cookies, from Service - Call Service with the below code it works without an issue - the music starts immediately.
code 1 which works:

Service: 
spotcast.start 
Entity: 
media_player.office_speaker 
Service Data (YAML, optional):
device_name: Office speaker 
entity_id: media_player.office_speaker 
uri: 'spotify:playlist:37i9dQZF1DX7cZxYLqLUJl' 
random_song: true 
shuffle: true

If I put the same as above in a script - Morning Alarm - it does not work anymore and throws the error in the subject
code 2 which does not work:
Script:

'1593159898420':
  alias: Morning Alarm
  sequence:
  - data:
      entity_id: media_player.office_speaker
      random_song: true
      shuffle: true
      uri: spotify:playlist:37i9dQZF1DX7cZxYLqLUJl
    entity_id: media_player.office_speaker
    service: spotcast.start

The error code is:

2020-06-26 11:31:06 INFO (MainThread) [homeassistant.components.script] Morning Alarm: Running script 2020-06-26 11:31:06 INFO (MainThread) [homeassistant.components.script] Morning Alarm: Executing step call service 2020-06-26 11:31:06 ERROR (MainThread) [homeassistant.components.script] Morning Alarm: Error executing script. Invalid data for call_service at pos 1: value should be a string for dictionary value @ data['entity_id'] 2020-06-26 11:31:06 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140331804021776] value should be a string for dictionary value @ data['entity_id'] Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 130, in handle_call_service connection.context(msg), File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1295, in _execute_service await handler.func(service_call) File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 207, in service_handler await script.async_turn_on(variables=service.data, context=service.context) File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 284, in async_turn_on await self.script.async_run(kwargs.get(ATTR_VARIABLES), context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 831, in async_run await run.async_run() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 555, in async_run await self._async_run() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 572, in _async_run await self._async_step(log_exceptions=not propagate_exceptions) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 153, in _async_step self, f"_async_{cv.determine_script_action(self._action)}_step" File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 656, in _async_call_service_step *self._prep_call_service_step(), blocking=True, context=self._context File "/usr/src/homeassistant/homeassistant/core.py", line 1222, in async_call processed_data = handler.schema(service_data) File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 272, in __call__ return self._compiled([], data) File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict return base_validate(path, iteritems(data), out) File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping raise er.MultipleInvalid(errors) voluptuous.error.MultipleInvalid: value should be a string for dictionary value @ data['entity_id']

Any ideas on what I am missing? Thank you very much.

There are 2 mentions of entity_id in your code.

Thank you for the notice, but removing the entity_id from data: does not fix it:


'1593159898420':
  alias: Morning Alarm
  sequence:
  - data:
      random_song: true
      shuffle: true
      uri: spotify:playlist:37i9dQZF1DX7cZxYLqLUJl
    entity_id: media_player.office_speaker
    service: spotcast.start

any ideas on what’s wrong with my code?

It did not work for me either - if you make an automation it will work.

Hi, can you give me an example? as if I try to call it from Services directly it works. If I want to use it in an automation - then it does not work and throws the above errors.

I send you an example later today…

1 Like

this works in my automation

image

WOW :smile: it worked - unbelievable - thank you very much.
I think it’s because of the force_playback ? and not stating the device directly?
that was weird.

It works now. Thank you very much @ha_user22323

1 Like

Trying to set up Spotcast.

My first script is this one.

spotify:
  alias: 'Spotify'
  sequence:
   - service: spotcast.start
     data:
       device_name: Onkyo
       uri: spotify:playlist:2vFYF85ujUdZpgpSbCM6g

I get an error after 30 redirects. Any ideas on solving this problem?

Logdetaljer (ERROR)
Logger: homeassistant.core
Source: custom_components/spotcast/__init__.py:262
First occurred: 7.54.58 (5 occurrences)
Last logged: 8.35.39

Error executing service: <ServiceCall script.spotify (c:0757966ad6f746cab79577bfa0c46564)>
Error executing service: <ServiceCall script.spotify (c:74da3b885d3e42228ae074642538108f)>
Error executing service: <ServiceCall script.spotify (c:8aa0c834bab847149c460f5f1061745b)>
Error executing service: <ServiceCall script.spotify (c:5bdfb384b7f148e8b89d486bca78703c)>
Error executing service: <ServiceCall script.spotify (c:c1606c8a62c5414f8367dacd4659bdf6)>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1276, in catch_exceptions
    await coro_or_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1295, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 207, in service_handler
    await script.async_turn_on(variables=service.data, context=service.context)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 284, in async_turn_on
    await self.script.async_run(kwargs.get(ATTR_VARIABLES), context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 831, in async_run
    await run.async_run()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 555, in async_run
    await self._async_run()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 572, in _async_run
    await self._async_step(log_exceptions=not propagate_exceptions)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 153, in _async_step
    self, f"_async_{cv.determine_script_action(self._action)}_step"
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 656, in _async_call_service_step
    *self._prep_call_service_step(), blocking=True, context=self._context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1299, in _execute_service
    await self._hass.async_add_executor_job(handler.func, service_call)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/spotcast/__init__.py", line 199, in start_casting
    access_token, expires = get_token_instance(account).get_spotify_token()
  File "/config/custom_components/spotcast/__init__.py", line 262, in get_spotify_token
    self._access_token, self._token_expires = st.start_session(self.sp_dc, self.sp_key)
  File "/usr/local/lib/python3.7/site-packages/spotify_token.py", line 19, in start_session
    headers=headers, cookies=cookies)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 665, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 665, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.7/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.

For some reason I’m not seeing this custom component in HACS…?

try the “+” sign in lower right corner.