In short the answer is that the only way to start spotify on a chromecast device is through this component nowadays. I’m on my phone so I will not detail it but it has to do with the token for the spotify media component is not powerful enough to start the app on chromecast.
sorry to be dumb, but could you please share a working script example?
i have your component working and it sees all my cast devices
I tried this
play_song:
alias: 'Play a Spotify track on Chromecast'
sequence:
- service: spotcast.start
data:
device_name: 'Master Bedroom Speaker'
uri: 'spotify:track:6xFXusME7FMMyMkPrIv2WJ'
yet checking config kicks up an error
You need to check the log for what error it is. I suspect that it is one of the following:
- You have not installed
spotcast
correctly. Check in devtools-> dev-service ifspotcast.start
is listed as a service. - ‘Master Bedroom Speaker’ is not an exact match for the chromecast device. Check the sensor.chromecast_devices for what devices are available
- Your spotify username and or password is incorrect. These should be the same as when you login on https://open.spotify.com
- You don’t have a premium subscription
1, Yes spotcast.start does appear in the dev tool list
2, ‘Master Bedroom Speaker’ was lifted straight from the devices_json:
3, it is correct because the sensor it populated with the list of devices
4, yes I do have a premium account
using the above I posted as a script I get the following error
Invalid config for [script]: expected dict for dictionary value @ data['script']['play_song']['sequence'][0]['data']. Got None
extra keys not allowed @ data['script']['play_song']['sequence'][0]['device_name']. Got 'Master Bedroom Speaker'
extra keys not allowed @ data['script']['play_song']['sequence'][0]['uri']. Got 'spotify:track:6xFXusME7FMMyMkPrIv2WJ'. (See /config/configuration.yaml, line 176). Please check the docs at https://home-assistant.io/components/script/
You need two extra spaces in front of the last 2 lines of your script. It is an indentation problem.
Amazing! Haven’t been able to try it yet but it seems my two days foray of setting up and MPD instance and Icecast server simply to start playlists in spotify (which I have used a total of 2 times) was completely in vain!
Great! On a side note I am checking with core devs who owns media_player.py because I think these should merge. There is one problem in that the official spotify component in HA used normal clientId and client-secret from spotify dev site which is not powerful enough to initiate playback on chromecast devices (hence this small component).
If I am to take over maintenance of that I would be greatful if someone else would join me
you’re kidding me!
I fell foul of the blooming indentation ahhhh!
many thanks
@fondberg thank you for trying to help with my clear stupidity
it does work yet as already mentioned HA doesn’t detect that the google device is playing anything
I also got some, probably silly error:
2019-05-02 16:35:00 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall script.spotify2 (c:c1e75e9bf17d45d398378972b6daa38f)> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1147, in _safe_execute await self._execute_service(handler, service_call) File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1160, in _execute_service await handler.func(service_call) File "/usr/local/lib/python3.7/site-packages/homeassistant/components/script/__init__.py", line 116, in service_handler context=service.context) File "/usr/local/lib/python3.7/site-packages/homeassistant/components/script/__init__.py", line 174, in async_turn_on kwargs.get(ATTR_VARIABLES), context) File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 131, in async_run await self._handle_action(action, variables, context) File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 210, in _handle_action action, variables, context) File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py", line 299, in _async_call_service context=context File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 88, in async_call_from_config domain, service_name, service_data, blocking=blocking, context=context) File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1138, in async_call self._execute_service(handler, service_call)) File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1162, 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 73, in start_casting access_token, expires = get_spotify_token(username=username, password=password) File "/config/custom_components/spotcast/__init__.py", line 43, in get_spotify_token import spotify_token as st ModuleNotFoundError: No module named 'spotify_token'
1, spotcast.start does appear in the dev tool list
2, ‘Wohnzimmer’ is a name used in chromecast.sensor:
3, the sensor it populated with the list of devices (does this mean my spotify credentials are correct?
4, yes I do have a premium account
My configuration.yaml:
spotcast: username: [email protected] password: hidden
My script:
(Please don’t ask me, why sometimes I cannot post here with proper intendation, hence the screenshot)
Sorry for these beginner questions! Thank you for providing this great component!
you need one more indent from - service down
spotify:
alias: 'Spotify'
sequence:
- service: spotcast.start
data:
device_name: 'Wohnzimmer'
uri: 'spotify:playlist:37i9dQZF1DX3yvAYDslnv8'
Thanks for your reply!
Added the indents, but still getting the same error.
The ModuleNotfound error disappeared for me after an extra restart of HA.
@fondberg
looking at the media_player on Github there seems to be two contributors cgtobi & balloob
I restarted several times now, but still getting the same errors.
Succesfully added the custom component but when try to play something with the following service, I get the error below.
{
“device_name” : “Google Home Speelkamer”,
“uri” : “spotify:playlist:37i9dQZF1DX3yvAYDslnv8”
}
No module named ‘spotify_token’
18:21 custom_components/spotcast/init.py (ERROR) - message first occured at 18:16 and shows up 3 times
awesome work man. I like your Spotify card and now this. I’ll start testing it soon and let you know of any issues.
Which version of HA are you running? I think my component requires 0.92 because the dependencies changed in that release to be specified in a manifest instead of in the python file.
If you are running 0.92 I would look in the logs for any errors importing spotify_token
@capstan1 ^^ you should also follow this
0.91.4. Will try again after an upgrade to 0.92