Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pair of Google Home device Stopped working #459

Open
7 of 8 tasks
Marcos-kp opened this issue Sep 26, 2024 · 43 comments
Open
7 of 8 tasks

Pair of Google Home device Stopped working #459

Marcos-kp opened this issue Sep 26, 2024 · 43 comments
Assignees
Labels
bug Something isn't working v5 Will be worked on in v5

Comments

@Marcos-kp
Copy link

Marcos-kp commented Sep 26, 2024

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]: 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_dc and sp_key values 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

@Marcos-kp Marcos-kp added the bug Something isn't working label Sep 26, 2024
@Marcos-kp
Copy link
Author

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

@bscheutjens
Copy link

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
Copy link
Author

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%.

@Marcos-kp Marcos-kp changed the title Only one Google Home device Stopped working Pair of Google Home device Stopped working Sep 27, 2024
@bscheutjens
Copy link

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
Copy link
Author

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

@Fatalmose
Copy link

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
Copy link

Peixeiro commented Oct 7, 2024

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
Copy link

Fatalmose commented Oct 7, 2024 via email

@Fatalmose
Copy link

And yes...
By creating a music group into Google Home in which i integrated the pair of Harman Kardon Citation One , HA sees that group and when i select music using Cast , it works again.
Very strange indeed...

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

@Fatalmose
Copy link

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

Yes i can confirm.
By creating a group into Google Home i made it work again.
But strange indeed....

@fcusson
Copy link
Collaborator

fcusson commented Oct 17, 2024

But strange indeed....

Chromecast is registering groups very differently then a sole speaker, so I'm not suprised, I have a feeling that the device creating problem is slow to register itself with spotify and going out of the timeout of the code

@Peixeiro
Copy link

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

I solved my problem by editing the speaker name (Xiaomi Smart watch) in the Google Home app and setting it the same as what I have in Home Assistant. For some reason the names were different.

@Fatalmose
Copy link

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.

@hatemsh
Copy link

hatemsh commented Oct 23, 2024

I have 3 Chromecast devices and none of them are showing in the source list
If I go here : https://developer.spotify.com/documentation/web-api/reference/get-a-users-available-devices
only the device that's currently playing music shows up in the list. As soon as I stop playing music on it, it disappears.
The same is true for groups, they don't show up unless they are currently playing music.

I can select my speakers / groups just fine from the Mac app and my Android phone app

Did Spotify change something in their API?

@fcusson
Copy link
Collaborator

fcusson commented Oct 23, 2024

@hatemsh no that's normal, and the whole reason spotcast exist.

A Chromecast device is not registered to a Spotify Account, that would be a mess to deal with when multiple user are in the same house, you can't have them registered to multiple accounts at the same time, so apps look at mDNS for devices and then a private spotify Api (not part of the public one) registers the spotify app under a specific user at request time.

That's what Spotcast is doing, the problem is, we can only register device we know, so we rely on the spotify integration in home assistant to provide the zeroconf detail to be able to talk to the Chromecast and register the account.

That's why you should always use entity ID when possible. Spotify ID are for devices already registered to your account or that you manage the registration separately.

@Fatalmose
Copy link

I have several ChromeCast players working fine with SpotCast using the Mini Média Player integration.
My pair of HK Citation One speakers also used to work fine using SpotCast and the Mini Media Player integration…
But now it stopped working on those…
Why..????

@hatemsh
Copy link

hatemsh commented Oct 24, 2024

@fcusson It was a naming problem. All of my devices were named "[Room] speaker" in the Google Home app but named "[Room] Speaker" (with capital S) in HA. I had one group that was named correctly both places but it strangely didn't work either.

I renamed everything everywhere manually to match, the device names in Google Home and device names as well as entity friendly names in HA, even the ones that were auto generated correctly. I then went to every speaker and said "play music" to refresh the names in Spotify and that's when it all started working.

@Fatalmose try to see if you didn't rename the devices that stopped working or something similar. You could also try doing what I did and change all of the names everywhere manually to match and try again (don't forget to go to the speakers after and say "play music" on each one individually)

@Fatalmose
Copy link

Fatalmose commented Oct 24, 2024 via email

@fcusson
Copy link
Collaborator

fcusson commented Oct 24, 2024

@Fatalmose any error logs?

I have a feeling this is just the device being slow to register with Spotify.

@Fatalmose
Copy link

Fatalmose commented Oct 24, 2024 via email

@Fatalmose
Copy link

@Fatalmose any error logs?

I have a feeling this is just the device being slow to register with Spotify.

About error logs.

failure , can not execute spot cast / start action , failed to get device id from Spotify.

@Fatalmose
Copy link

@Fatalmose any error logs?
I have a feeling this is just the device being slow to register with Spotify.

About error logs.

failure , can not execute spot cast / start action , failed to get device id from Spotify.

Do you think there is a solution…?

@fcusson
Copy link
Collaborator

fcusson commented Oct 25, 2024

About error logs.

failure , can not execute spot cast / start action , failed to get device id from Spotify.

@Fatalmose, that's not a error log, that's a notification, you should have a traceback in your logs.

@Fatalmose
Copy link

Fatalmose commented Oct 25, 2024 via email

@fcusson
Copy link
Collaborator

fcusson commented Nov 19, 2024

@Fatalmose, I don't think we will be able to solve the issue in the current major version of Spotcast, since we are dependant on the main Spotify Integration to report the device before we can confirm it is available. This will have to wait for the v5 in which we have control over the Spotify API and are able to monitor devices availability independently of the Spotify Integration

@Fatalmose
Copy link

Fatalmose commented Nov 20, 2024 via email

@fcusson
Copy link
Collaborator

fcusson commented Dec 5, 2024

Hi @Fatalmose, the beta for V5 have been out for a couple of weeks now. Just wanted to verify if you had a chance to test it and check if it solved your issue?

@Fatalmose
Copy link

Fatalmose commented Dec 5, 2024 via email

@Fatalmose
Copy link

Not working for me.
My HK Citation One speakers are switched on correctedly when media is selected but no sound is comming up.
After a few seconds they switch of automatically.
I dont have this issue on other ChromeCast speakers.
My HK speakers stopped working after Core 9.x.x

@fcusson
Copy link
Collaborator

fcusson commented Dec 5, 2024

do you have any error message regarding unhandled message by the chromecast controller? If not, could you enable debug log (Click on link and then enable debug logging)

Open your Home Assistant instance and show an integration.

There might be more I can dig in with the debug logs, they are much more useful in the new version

@Fatalmose
Copy link

No error message this time…
Debug log switched on.

@fcusson
Copy link
Collaborator

fcusson commented Dec 5, 2024

then you just need to reattempt what you where doing and deactivate the debug log, it wiull download a log file for you, you can provide it in the ticket

@Fatalmose
Copy link

Fatalmose commented Dec 5, 2024 via email

@fcusson
Copy link
Collaborator

fcusson commented Dec 5, 2024

Oh I don't know if its goign to work well on an iphone. There should be normally a log file that gets downloaded on your device. That's what I would need.

@Fatalmose
Copy link

Fatalmose commented Dec 5, 2024 via email

@Fatalmose
Copy link

Fatalmose commented Dec 5, 2024 via email

@Fatalmose
Copy link

Enregistreur: homeassistant.core
Source: core.py:2822
S'est produit pour la première fois: 19:35:26 (1 occurrences)
Dernier enregistrement: 19:35:26

Error executing service: <ServiceCall spotcast.start (c:01JEC1N4QGP8PAGV4V1Z8SBDKS): entity_id=media_player.disco_club, uri=spotify:playlist:5tHnFa8VyGDd5C8mhrbb3J, ignore_fully_played=False, random_song=False, limit=20, repeat=off, start_volume=101, offset=0, force_playback=False, shuffle=False>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/core.py", line 2822, in _run_service_call_catch_exceptions
await coro_or_task
File "/usr/src/homeassistant/homeassistant/core.py", line 2852, in _execute_service
return await self._hass.async_add_executor_job(target, service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/spotcast/init.py", line 378, in start_casting
raise exc
File "/config/custom_components/spotcast/init.py", line 273, in start_casting
spotify_device_id = spotcast_controller.get_spotify_device_id(
account, spotify_device_id, device_name, entity_id
)
File "/config/custom_components/spotcast/spotcast_controller.py", line 304, 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 140, in get_spotify_device_id
raise HomeAssistantError("Failed to get device id from Spotify")
homeassistant.exceptions.HomeAssistantError: Failed to get device id from Spotify

@Fatalmose
Copy link

Cette erreur provient d'une intégration personnalisée

Enregistreur: custom_components.spotcast.spotcast_controller
Source: custom_components/spotcast/spotcast_controller.py:133
intégration: Spotcast (documentation, problèmes)
S'est produit pour la première fois: 19:35:26 (1 occurrences)
Dernier enregistrement: 19:35:26

No device with id "435b275f7e164cc2667661e73f62628b" known by Spotify

@Fatalmose
Copy link

Cette erreur provient d'une intégration personnalisée

Enregistreur: custom_components.spotcast.spotcast_controller
Source: custom_components/spotcast/spotcast_controller.py:138
intégration: Spotcast (documentation, problèmes)
S'est produit pour la première fois: 19:35:26 (1 occurrences)
Dernier enregistrement: 19:35:26

Known devices: [Device(device_id='af8567bd6fc46e7d3461a23fe206175e', is_active=False, is_private_session=False, is_restricted=False, name='Disco Left', device_type=<DeviceType.CAST_AUDIO: 'CastAudio'>, volume_percent=51, supports_volume=True), Device(device_id='58f1c11f3b56837187163fd9072a644b3e74a66d', is_active=False, is_private_session=False, is_restricted=False, name='Marshall Véranda', device_type=<DeviceType.SPEAKER: 'Speaker'>, volume_percent=50, supports_volume=True)]

@fcusson
Copy link
Collaborator

fcusson commented Dec 5, 2024

oh sorry, I misunderstood and though you already had tested the beta because of one of your message. Please attempt with the beta when you have the time, see if it changes the behavior otherwise, please provide the logs so I can see what is going on.

The current production version doesn't log unknown messages, I have a feeling this is the problem in the Chromecast exchange

@Fatalmose
Copy link

Fatalmose commented Dec 5, 2024 via email

@fcusson
Copy link
Collaborator

fcusson commented Dec 5, 2024

@Fatalmose you can update to the beta from HACS directly, simply search for Spotcast and then cilck three dots -> redownload You can then select a specific version you will see there is a couple of version in the format 5.0.0-b<>build-number they are all marked pre-release.

All documentation is in the dev branch here on github and for the setup, you will see that it was moved to the UI, so you will have to re configure spotcast. If you intend to potentially switch back, I would suggest you keep your yaml config, but you will have an error message saying that spotcast doesn't support it (this error doesn't break anything)

@Fatalmose
Copy link

Fatalmose commented Dec 5, 2024 via email

@fcusson fcusson added the v5 Will be worked on in v5 label Dec 10, 2024
@fcusson fcusson modified the milestone: V5 Release Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v5 Will be worked on in v5
Projects
None yet
Development

No branches or pull requests

6 participants