spotcast: Pair of Google Home device Stopped working
Bug Ticket
Describe the bug
<I’m experiencing an issue with the Spotcast integration in Home Assistant. Only one of my two Google Home devices is working correctly with Spotcast. When attempting to use the service for the non-working device, I receive an error.
Initial State
I have two Google Home devices set up in my home. Both devices are visible and controllable through the Spotify app on my iPhone and PC. Both Google Home devices worked fine with Spotcast, but one suddendly stopped working.
Issue with Non-working Device:
When I call the Spotcast service for the non-working Google Home in Home Assistant, I get the error: “HomeAssistantError: Failed to get device id from Spotify” Investigating further, I checked the Spotify API response for available devices:
The non-working Google Home is not visible in this API response when queried through Home Assistant. However, the device is visible in the Spotify app on my iPhone and PC.
Temporary Visibility in Spotify API:
If I start playback on the non-working Google Home speaker through the Spotify app on my phone:
The device then becomes visible in the Spotify API response. I can retrieve its device ID at this point.
Attempted Solution and New Error:
After getting the device ID during this temporary visibility:
I add the device ID to the Home Assistant service call. I wait for the device to go inactive (stop playing). When I try to use the Spotcast service again, I get a new error: “HomeAssistantError: http status: 404, code:-1 - [https://api.spotify.com/v1/me/player/play?device_id=[device_id](https://api.spotify.com/v1/me/player/play?device_id=[device_id)]: Device not found, reason: None”
Additional Attempts:
I tried using the “select source” service call in Home Assistant before calling the Spotcast start service. This didn’t resolve the issue; the problem persists.
Additional Information
The issue only affects one of the two Google Home devices; the other works fine. The affected device works correctly when controlled directly through the Spotify app on my iPhone.>
Troubleshooting
Make sure to validate all the elements before submitting the ticket (Exception to the steps marked as optional)
- Using latest version of spotcast
- Using latest stable version of Home Assistant
- I have setup the Spotify integration in Home Assistant
- I have renewed my
sp_dcandsp_keyvalues and restarted Home Assistant (see README) - (optional) I have Spotify Premium
- (optional) I am using multiple accounts
- (optional) I’m attaching relevant logs with level debug for component spotcast (see README)
- (optional) I’m using entity_id in the service call and have tried device_name but the issue remains
Environment
- Installation type: [HA_OS]
- HA version: [ 2024.9.2]
- spotcast version: [ v3.8.1]
Configuration
<spotcast:
sp_dc: !secret spotify_sp_dc
sp_key: !secret spotify_sp_key
country: BR>
Service Call
If relevant, provide a yaml of the service call or explain the action taken to replicate the issue.
For Spotcast Start in node red I didn’t change anything to my service and it just stopped working. Ihave tried multiple options, with entity_id, device_name and device_id. I copied the service from the working Cast device and still won’t work. Below is one example:
<{
"uri": "spotify:playlist:xxxx",
"spotify_device_id": "my_device_id",
"random_song": true,
"shuffle": true
}>
Logs
- normal|debug Here are some logs from the service call variations I tried:
<[140397998605072] Unexpected exception
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 271, in _internal_call
response.raise_for_status()
File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/me/player/play?device_id=My_device_id
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2811, in _execute_service
return await self._hass.async_add_executor_job(target, service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/__init__.py", line 327, in start_casting
spotcast_controller.play(
File "/config/custom_components/spotcast/spotcast_controller.py", line 374, in play
client.start_playback(**kwargs)
File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 1821, in start_playback
return self._put(
^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 338, in _put
return self._internal_call("PUT", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/spotipy/client.py", line 293, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/me/player/play?device_id=My_device_id:
Device not found, reason: None
HTTP Error for PUT to https://api.spotify.com/v1/me/player/play?device_id=My_device_id with Params: {} returned 404 due to Device not found
[140397998605072] Unexpected exception
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2811, in _execute_service
return await self._hass.async_add_executor_job(target, service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/__init__.py", line 256, in start_casting
spotify_device_id = spotcast_controller.get_spotify_device_id(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotcast_controller.py", line 296, in get_spotify_device_id
spotify_device_id = spotify_cast_device.get_spotify_device_id(me_resp["id"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotcast_controller.py", line 137, in get_spotify_device_id
raise HomeAssistantError("Failed to get device id from Spotify")
homeassistant.exceptions.HomeAssistantError: Failed to get device id from Spotify
Known devices: [{'id': 'My_device_id', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'Quarto L', 'supports_volume': True, 'type': 'CastAudio', 'volume_percent': 0}]
Known devices: [{'id': 'My_device_id', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'Quarto L', 'supports_volume': True, 'type': 'CastAudio', 'volume_percent': 20}]
Known devices: [{'id': 'My_device_id', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'Quarto L', 'supports_volume': True, 'type': 'CastAudio', 'volume_percent': 20}, {'id': 'My_device_id', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'iPhone', 'supports_volume': False, 'type': 'Smartphone', 'volume_percent': 100}]
Known devices: [{'id': 'My_device_id', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'Quarto L', 'supports_volume': True, 'type': 'CastAudio', 'volume_percent': 15}]
Known devices: [{'id': 'My_device_id', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'Quarto L', 'supports_volume': True, 'type': 'CastAudio', 'volume_percent': 0}, {'id': 'My_device_id', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'iPhone', 'supports_volume': False, 'type': 'Smartphone', 'volume_percent': 100}]
No device with id "My_device_id" known by Spotify
[140397998605072] Unexpected exception
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
response = await hass.services.async_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2811, in _execute_service
return await self._hass.async_add_executor_job(target, service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/__init__.py", line 256, in start_casting
spotify_device_id = spotcast_controller.get_spotify_device_id(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/spotcast/spotcast_controller.py", line 294, in get_spotify_device_id
spotify_cast_device.start_spotify_controller(access_token, expires)
File "/config/custom_components/spotcast/spotcast_controller.py", line 94, in start_spotify_controller
sp.launch_app()
File "/config/custom_components/spotcast/spotify_controller.py", line 128, in launch_app
raise LaunchError(
custom_components.spotcast.error.LaunchError: Timeout when waiting for status response from Spotify app
>
Additional context
<Add any other context about the problem here.>About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 43
Creating a group into Google Home solved the problem for using media on ChromeCast Harman Kardon Citation One speakers. But the problem remains using the Mini Media Player integration that uses Spot Cast / Start in the Yaml config. The HK Citation One speakers are switched on but no sound is coming up , getting failure , can not execute spot cast / start action , failed to get device id from Spotify.