fondberg / spotcast

Home assistant custom component to start Spotify playback on an idle chromecast device as well as control spotify connect devices
Apache License 2.0
671 stars 97 forks source link

Pair of Google Home device Stopped working #459

Open Marcos-kp opened 2 weeks ago

Marcos-kp commented 2 weeks ago

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=%5Bdevice_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)

Environment

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

<[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

Marcos-kp commented 2 weeks ago

Weird that I can play in the Group that I made in the google home app where both speakers are.

bscheutjens commented 1 week ago

I seem to have a similar issue. I use Spotcast to start a Spotify playlist when I start working in the morning (based on power consumption). This worked great for a while, but stopped working some time ago. I tried fixing it today by refreshing the sp_dc and sp_key values, but I still got the error ("Failed to get device id from Spotify"). Based on the description in this issue I tried starting the playlist on two other devices that I have and those do work, so I seem to be doing the correct thing.

The device that isn't working, does work properly when using Spotify on my Windows desktop and when using the Spottily app on my phone.

In my case the device that doesn't work actually is a set of two devices that I've configured to be a single stereo device (so in the Google Home app I see just one device). But as already stated, it used to worked with Spotcast, so that shouldn't be a problem.

Marcos-kp commented 1 week ago

Exaclty the same scenario @bscheutjens ! My broken speaker is a pair of Google Nest Minis. My workaround was to play music in my speaker group and lower the volume of the working speaker to 0%.

bscheutjens commented 1 week ago

In my case I have a pair of HK Citation One. But... Your comment made me think of something. I have created a group with just that one (pair of) speaker and use Spotcast to play using that group and that also works. It is a workaround and you don't have to set the volume of that other speaker to 0%.

Marcos-kp commented 1 week ago

Awesome! I had no idea you could create a group of "one" speaker. Thanks!

Fatalmose commented 4 days ago

Hello,

Same issue. My Harman Kardon Citation One do not respond anymore using Google Cast and Spot Cast. Getting failure , can not execute spot cast / start action , failed to get device id from Spotify. This is really getting annoying.... Everytime there are changes , things on which you spend hours stop working... Altough I know that many people are working hard to make HA an exceptional experience for which i'm great full .

Peixeiro commented 3 days ago

Have the same issue!

Work on Xiaomi Smart Speaker IR, failed on Xiaomi Samrt Clock, but work on a Group of this two Google cast speakers.

Fatalmose commented 3 days ago

Talking about creating a Group. I’d tried to do so but can not select any media in the Group.

Le lun. 7 oct. 2024 à 18:26, Peixeiro @.***> a écrit :

Have the same issue!

Work on Xiaomi Smart Speaker IR, failed on Xiaomi Samrt Clock, but work on a Group of this two Google cast speakers.

— Reply to this email directly, view it on GitHub https://github.com/fondberg/spotcast/issues/459#issuecomment-2397382385, or unsubscribe https://github.com/notifications/unsubscribe-auth/BGEH4FWMKJFD3JBDA3PGIETZ2KY5BAVCNFSM6AAAAABO5KRARCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJXGM4DEMZYGU . You are receiving this because you commented.Message ID: @.***>