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

Hi, this looks as it succeded playing the track. If your issue is with the google home device not showing status playing the issue is not with spotcast but rather how pychromecast and home-assistant works together.
One last thing you can try is to disable the sensor for spotcast which uses pychromecast (if that could interfer in your setup)

With the release of version 105 does the Spotify integration now allow for the same functionality as Spotcast? I havenā€™t been able to find much documentation on how to play a Spotify song/playlist on a Google Home. Can anyone tell me if it is possible or if we still need this custom component to get it to work?

Asked and answered in this thread already. Short answer is that it is still needed.

SOLVED:
Apparently after removing the chromecasts and adding them again all works now, amazing! Not I just need a smart way to trigger them playing :slight_smile:


Hey, so I am absolute excited about the possibilities opened up by the community, I must say!

But I am somehow experiencing kind of the same problem as described before:

2020-02-08 15:32:17 INFO (SyncWorker_0) [pychromecast] Quiting current app
2020-02-08 15:32:17 INFO (SyncWorker_0) [pychromecast.controllers] Receiver:Stopping current app 'CC1AD845'
2020-02-08 15:32:17 INFO (SyncWorker_0) [pychromecast.controllers] Not launching app CC1AD845 - already running
2020-02-08 15:32:21 INFO (Thread-3) [pychromecast.controllers] Receiver:Launching app CC1AD845
2020-02-08 15:32:34 DEBUG (MainThread) [custom_components.spotcast] cast info: None
2020-02-08 15:32:34 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140017307160912] 'NoneType' object has no attribute 'host'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1226, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1251, in _execute_service
    await handler.func(service_call)
  File "/config/custom_components/spotcast/__init__.py", line 156, in start_casting
    spotify_cast_device = SpotifyCastDevice(hass, call.data.get(CONF_DEVICE_NAME), call.data.get(CONF_ENTITY_ID))
  File "/config/custom_components/spotcast/__init__.py", line 207, in __init__
    self.castDevice = self.getChromecastDevice(device_name)
  File "/config/custom_components/spotcast/__init__.py", line 218, in getChromecastDevice
    host = str(cast_info.host)
AttributeError: 'NoneType' object has no attribute 'host'

The service call Iā€™m doing is

entity_id: media_player.room1
uri: 'spotify:playlist:ID'
random_song: true
repeat: track

What did I do wrong? :-/

Edit:
Spotcastversion: v2.6.1
HASS-core version: 0.105.2

I think there are some issues in home assiatant with chromecast devices and their friendly name.

Please use the friendly name as device_name instead of entity_id

Hi, Iā€™ve just tested and disabling the spotcast sensor doesnā€™t work either. If I find the solution I will post here. Anyway, thank you very much for your help.

Not sure if this was discovered already, but I noticed that it works flawlessly on my google home mini but both my google hubā€™s are not recognized as valid chromecast devices

Do they show up in home assistant if you look at the devtools > states?

Yes they do and I can send tts commands to them as well

In that case I donā€™t understand what you mean with spotcast not recognizing your hub devicesā€¦

Can you explain what you are trying to do and what doesnā€™t work?

Iā€™m not sure when this started happening, but iā€™ve noticed my spotcast is no longer working, this was working brilliantly for quite some time

2020-02-15 13:23:27 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.play_music_when_beata_arrives_home. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 443, in action
    await script_obj.async_run(variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 190, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 273, in _handle_action
    await self._actions[_determine_action(action)](action, variables, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 355, in _async_call_service
    context=context,
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 97, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context
  File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1260, in _execute_service
    await handler.func(service_call)
  File "/config/custom_components/spotcast/__init__.py", line 158, in start_casting
    spotify_device_id = spotify_cast_device.getSpotifyDeviceId(client)
  File "/config/custom_components/spotcast/__init__.py", line 261, in getSpotifyDeviceId
    raise HomeAssistantError('Failed to get device id from Spotify')
homeassistant.exceptions.HomeAssistantError: Failed to get device id from Spotify

Make sure you are o the latest spotcast and home assiatant >= 1.05

Trying to send a playlist to my google home hub but it complains that it canā€™t find it (even though HA says itā€™s there because it is visible in the states overview and responds when interacting with it)

This is what I send:

uri: 'spotify:playlist:37i9dQZF1DX3yvAYDslnv8'
random_song: true
entity_id: media_player.kantoor_hub

This is whatā€™s in the log

2020-02-15 16:07:41 ERROR (MainThread) [custom_components.spotcast] Could not find device Kantoor Google Hub from hass.data, falling back to pychromecast scan
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 INFO (MainThread) [pychromecast] Querying device status
2020-02-15 16:07:50 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.139941186148048] Could not find device with name Kantoor Google Hub
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1226, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1251, in _execute_service
    await handler.func(service_call)
  File "/config/custom_components/spotcast/__init__.py", line 156, in start_casting
    spotify_cast_device = SpotifyCastDevice(hass, call.data.get(CONF_DEVICE_NAME), call.data.get(CONF_ENTITY_ID))
  File "/config/custom_components/spotcast/__init__.py", line 207, in __init__
    self.castDevice = self.getChromecastDevice(device_name)
  File "/config/custom_components/spotcast/__init__.py", line 233, in getChromecastDevice
    raise HomeAssistantError('Could not find device with name {}'.format(device_name))
homeassistant.exceptions.HomeAssistantError: Could not find device with name Kantoor Google Hub

It does work perfectly on my google home miniā€™s but I get these errors only on the Google Hubā€™s that I have

Brilliant!!! Thanks so much for this component. Took a while before I found it. Absolutely ā€œmust haveā€ to make the Spotify integration work on Google Cast devices. Thanks!!!

When i try to play spotify in my chromecast audio device i always get this error:

2020-02-17 12:06:02 ERROR (MainThread) [custom_components.spotcast] Could not find device Chromecast Audio from hass.data, falling back to pychromecast scan

How to have also this device working with spotify like all the other alexa devices?

Got the same issue

Please upgrade to latest because there has been mismatches between deps for spotcast and hass.

If it still canā€™t find the device with the friendly name please post what the attributes look for the entity in the states list. (media_player.xxx)

Here it is the actual state of my device. I just tried to play right now but had the same errorā€¦


In the list of devices i get the right name of it ā€œChromecast Audioā€.
My actual release is 2.7.2 which is the latest available in HACS.

Iā€™ve installed Spotcast using HACS and can see my Chromecast devices in the Lovelace Custom Card however when I attempt to cast to them I receive:

Failed to call service spotcast/start. Service not found.

Iā€™ve added to the following to my configuration.yaml file and have successfully logged into the Spotify website using the credentials (they were generated using the ā€œSet device passwordā€ functionality) so I know they are correct:

spotcast:
  username: spotify_username
  password: spotify_password

I am brand new to HA so itā€™s highly likely Iā€™ve done sometthing dumb but it doesnā€™t seem like Iā€™ve missed anything. Do the username and password need quotation marks around them or anything?

Questions

  1. Can you start spotify on that device from chrome using open.spotify.com?
  2. Are other devices working with spotcast?

If both answers are yes I ca prepare a special release for you with much more debug