spotcast icon indicating copy to clipboard operation
spotcast copied to clipboard

Can't find device with name xxx

Open alitheg opened this issue 1 year ago • 13 comments

The problem

When I use entity ID to switch playback, I get an error (I've tried this with a device with no apostrophe in it too):

Screenshot 2024-12-05 at 11 21 01

However if I copy and paste that value and use device_name, it works:

Screenshot 2024-12-05 at 11 21 06

System Health details

System Information

version core-2024.12.0
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.13.0
os_name Linux
os_version 6.6.63-haos
arch x86_64
timezone Europe/London
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
HACS Data ok
GitHub API Calls Remaining 5000
Installed Version 2.0.1
Stage running
Available Repositories 1485
Downloaded Repositories 30
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 14.0
update_channel stable
supervisor_version supervisor-2024.11.4
agent_version 1.6.0
docker_version 27.2.0
disk_total 38.7 GB
disk_used 33.6 GB
healthy true
supported true
host_connectivity true
supervisor_connectivity true
ntp_synchronized true
virtualization kvm
board ova
supervisor_api ok
version_api ok
installed_addons ESPHome Device Compiler (2024.11.2), Terminal & SSH (9.15.0), File editor (5.8.0), Whisper (2.3.0), Prometheus Node Exporter (1.0.2), Let's Encrypt (5.2.7), NGINX Home Assistant SSL proxy (3.11.1), ESPresense Companion (1.0.14), openWakeWord (1.10.0), Matter Server (6.6.1), OpenThread Border Router (2.12.2)
Dashboards
dashboards 14
resources 20
views 16
mode storage
Recorder
oldest_recorder_run 26 November 2024 at 22:33
current_recorder_run 5 December 2024 at 09:32
estimated_db_size 889.65 MiB
database_engine sqlite
database_version 3.45.3
Spotify
api_endpoint_reachable ok

Spotcast Version

v4.0.0

What type of installation are you running?

Home Assistant OS

Diagnostics information

home-assistant_spotcast_2024-12-05T11-24-18.332Z.log

Example YAML snippet

action: spotcast.start
data:
  entity_id: media_player.alastair_s_echo_pop


### Anything in the logs that might be useful for us?

_No response_

### Additional information

_No response_

alitheg avatar Dec 05 '24 11:12 alitheg

Hi @alitheg,

Technically Spotcast is only compatible for Chromecast and Spotify Connect Devices. Echoes are not compatible, it might work in some edge cases, but very unstable and untested. I'm going to close this ticket as this is a duplicate of #403 which we are already tracking.

I'm hoping someone with an echo will submit a PR, but in the meantime, I personnaly cannot solve this as I do not own any echo devices.

fcusson avatar Dec 05 '24 12:12 fcusson

Hi @fcusson ah I see - are the echoes not Spotify connect devices? They all show up in my Spotify Connect list when I'm using it! If not that's fine, I can also take a look at the source of this issue and see if I can find anything.

alitheg avatar Dec 05 '24 12:12 alitheg

@alitheg no they have there own protocol (called skills), just like Chromecast. Also to be more precise, currently, the Spotify Connect need to be preregistered to the account (thats mostly spotify applications running in different environment, like a console, phone, computer) If they are un registered, they cannot start playback with the public API. There is a registration handshake that needs to be done using a private API (the reason we use the SP_DC and SP_KEY instead of the OAuth for that). @fondberg, the original creator of the project was able to replicate the handshake for Chromecast. I'm currently working in V5 on the Spotify Connect version of that handshake.

For echo device, I would need someone to do some network protocol scanning while calling playback on an echo device in his network. That way we could try and understand how we can retro engineer the protocol and make it work.

fcusson avatar Dec 05 '24 12:12 fcusson

Also, just to clarify, Spotify Apps also integrate mDNS auto discovery for network connected speakers like chromecast and echo devices. When they show up in your list of devices they aren't "Spotify Connect" devices in the purest sense of the term, but just "Spotify Compatible" device.

fcusson avatar Dec 05 '24 12:12 fcusson

Got you - that makes sense. I've been looking through the logs and the code and I can see why it works for me with device_name and not entity_id - the first thing you do with device_name is go and ask Spotify for a device with that name, which it returns successfully. With entity_id it instead creates a SpotifyCastDevice (which, as you said is what you officially support) and that doesn't work because it's not a Chromecast device.

Would you accept a PR that gets the "friendly name" from the entity ID if it's set and Chromecast fails, then uses _getSpotifyConnectDeviceId on that, if I can get it working?

alitheg avatar Dec 05 '24 13:12 alitheg

@alitheg, with the new way of working with V5 it might not be necessary. If the device can be found found based on its name alone, that would mean its available through Get Available Devices. Could you check if you can see the device in the list of available ones. If so, V5 will create a media_player instance specifically for that device and let you use it for playback.

fcusson avatar Dec 05 '24 14:12 fcusson

Yup it's in available devices, and the service call works perfectly using name alone.

alitheg avatar Dec 05 '24 14:12 alitheg

ok so, that would mean this will be fully fixed with the beta, you'll simply have to call the proper media_player representing the Spotify Connect device

fcusson avatar Dec 05 '24 14:12 fcusson

Aha ok amazing. I'll give it a shot :)

alitheg avatar Dec 05 '24 15:12 alitheg

Hello, I also have that problem. Spotcast don't find my Google speakers. I can play from my emby or radio browser.

2024-12-05 18:34:01.494 ERROR (SyncWorker_6) [custom_components.spotcast.spotcast_controller] Could not find device Głośniki Google from hass.data
2024-12-05 18:34:01.495 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall spotcast.start (c:01JEBY570PXCQ96C4WQ734MT8F): entity_id=media_player.glosniki, uri=spotify:track:0IBq53Ctm1aS0YTEDdZqUv, random_song=False, ignore_fully_played=False, limit=20, shuffle=False, repeat=off, force_playback=False, offset=0, start_volume=101>
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/homeassistant/core.py", line 2822, in _run_service_call_catch_exceptions
    await coro_or_task
  File "/usr/local/lib/python3.13/site-packages/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 296, in get_spotify_device_id
    spotify_cast_device = SpotifyCastDevice(
        self.hass,
        device_name,
        entity_id,
    )
  File "/config/custom_components/spotcast/spotcast_controller.py", line 61, in __init__
    self.castDevice = self.get_chromecast_device(device_name)
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/spotcast_controller.py", line 87, in get_chromecast_device
    raise HomeAssistantError(
        "Could not find device with name {}".format(device_name)
    )
homeassistant.exceptions.HomeAssistantError: Could not find device with name Głośniki Google
2024-12-05 18:34:01.505 ERROR (SyncWorker_3) [custom_components.spotcast.spotcast_controller] Could not find device Głośniki Google from hass.data
2024-12-05 18:34:01.505 ERROR (MainThread) [homeassistant.core] Error executing service: <ServiceCall spotcast.start (c:01JEBY58MX0MKWRYEP776ST4XZ): entity_id=media_player.glosniki, uri=spotify:track:0IBq53Ctm1aS0YTEDdZqUv, random_song=False, ignore_fully_played=False, limit=20, shuffle=False, repeat=off, force_playback=False, offset=0, start_volume=101>
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/homeassistant/core.py", line 2822, in _run_service_call_catch_exceptions
    await coro_or_task
  File "/usr/local/lib/python3.13/site-packages/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 296, in get_spotify_device_id
    spotify_cast_device = SpotifyCastDevice(
        self.hass,
        device_name,
        entity_id,
    )
  File "/config/custom_components/spotcast/spotcast_controller.py", line 61, in __init__
    self.castDevice = self.get_chromecast_device(device_name)
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/config/custom_components/spotcast/spotcast_controller.py", line 87, in get_chromecast_device
    raise HomeAssistantError(
        "Could not find device with name {}".format(device_name)
    )
homeassistant.exceptions.HomeAssistantError: Could not find device with name Głośniki Google

Regards.

PrzemekSkw avatar Dec 05 '24 17:12 PrzemekSkw

@PrzemekSkw please open a new ticket and provide all relevant information. This ticket is specifically for an echo device not a chromecast device, so I will need more details from you

fcusson avatar Dec 05 '24 18:12 fcusson

@PrzemekSkw please open a new ticket and provide all relevant information. This ticket is specifically for an echo device not a chromecast device, so I will need more details from you

Hi, before I open new issue I want to check beta v5.0.0b-14 but after I fill the fields Name, Auth ID, Auth key I was redirected to spotify authorisation site and get: INVALID_CLIENT: Invalid client. Now even if I remove integration and ad it again I'm still redirected to that info and cannot open that popup window to fill that credentials. Regards

PrzemekSkw avatar Dec 05 '24 18:12 PrzemekSkw

@PrzemekSkw Even more reason to open a new ticket. I don't want to take over a ticket for an unrelated issue. Please look in your log, you should have an error log regarding the config error

fcusson avatar Dec 05 '24 19:12 fcusson