homeassistantcomponent_spotifyplus: [Errno 111] Connection refused') when trying to activate connection with Denon/Heos device

System Health details

System Information

version core-2024.12.5
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.66-haos
arch x86_64
timezone Europe/Brussels
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 1495
Downloaded Repositories 20
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.1
update_channel stable
supervisor_version supervisor-2024.12.0
agent_version 1.6.0
docker_version 27.2.0
disk_total 43.6 GB
disk_used 21.5 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 Samba share (12.3.2), Duck DNS (1.12.5), File editor (5.8.0), MariaDB (2.7.1), Mosquitto broker (5.1), Nginx Proxy Manager (1.0.1), Node-RED (18.1.1), Terminal & SSH (9.16.0), phpMyAdmin (0.11.0), Samba Backup (5.2.0), Z-Wave JS (0.9.0), Z-Wave JS to MQTT (0.19.1), Portainer (2.0.0), Vaultwarden (Bitwarden) (0.23.7), go2rtc (1.9.7), ESPHome Device Builder (2024.12.2), AdGuard Home (5.1.1), Music Assistant Server (2.3.4), Matter Server (6.6.1)
Dashboards
dashboards 4
resources 11
views 32
mode storage
Miele
component_version 2024.12.0
reach_miele_cloud ok
Recorder
oldest_recorder_run 28 December 2024 at 22:50
current_recorder_run 30 December 2024 at 23:56
estimated_db_size 109.82 MiB
database_engine sqlite
database_version 3.45.3
Spotify
api_endpoint_reachable ok
SpotifyPlus
integration_version v1.0.76
clients_configured 1: quizzical (premium)
api_endpoint_reachable ok

Checklist

  • I have enabled SmartInspect debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of any previous issues…

Describe the issue

As already discussed in this post: https://community.home-assistant.io/t/spotifyplus-integration/698651/404?u=quizzical

I’m getting Connection refused errors when trying to connect to a device (that is not already available) using the spotifyplus.player_transfer_playback service. When calling the same service a second time, it works.

I have the impression the first time it is using the wrong port number.

Reproduction steps

  1. Ensure that the device I want to playback on is not available for the moment to Home Assistant (e.g. by having another spotify user connect to the device)
  2. Call the spotifyplus.player_transfer_playback service with these options: { “device_id”: “REDACTED”, “play”: “True”, “refresh_device_list”: “True”, “force_activate_device”: “True”, “delay”: 7 }
  3. I get the following error: HomeAssistantError: Validation error: SAM0001E - An unhandled exception occured while processing method “GetInformation”. HTTPConnectionPool(host=‘192.168.0.139’, port=49446): Max retries exceeded with url: /zc?action=getInfo&version=2.7.1 (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x7fa78b7777a0>: Failed to establish a new connection: [Errno 111] Connection refused’)) …
  4. Call the same service again.
  5. The music will start playing succesfully on the device. The debug logs below show these steps.

Debug logs

2024-12-31 09:57:09.119 DEBUG (MainThread) [custom_components.spotifyplus] Processing service call 'player_transfer_playback' in async 'service_handle_spotify_command' method
2024-12-31 09:57:09.121 DEBUG (MainThread) [custom_components.spotifyplus] Entity id value of 'media_player.spotifyplus_quizzical' was resolved to MediaPlayerEntity instance for the 'player_transfer_playback' method call
2024-12-31 09:57:09.122 DEBUG (MainThread) [custom_components.spotifyplus] Executing 'player_transfer_playback' service on media player 'SpotifyPlus quizzical'
2024-12-31 09:57:09.125 DEBUG (SyncWorker_2) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Getting Spotify Connect Player state
2024-12-31 09:57:09.126 DEBUG (SyncWorker_2) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Currently selected Source: 'Bathroom'
2024-12-31 09:57:09.224 DEBUG (SyncWorker_2) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Transferring playback from source device name: 'Galaxy A54 5G' (id=71948c035bb6c1490496832696428994aa384373)
2024-12-31 09:57:12.057 DEBUG (SyncWorker_2) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Transferring playback to target device name: 'Bathroom (4bbb98e5f1f833de7e7efb6d56ee3d2cddc7571d)'
2024-12-31 09:57:13.016 DEBUG (SyncWorker_2) [custom_components.spotifyplus] 'SpotifyPlus quizzical': SpotifyApiError while transferring playback source; resetting source to: 'Bathroom'
2024-12-31 09:57:13.024 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140357692437792] SAM0001E - An unhandled exception occured while processing method "GetInformation".
HTTPConnectionPool(host='192.168.0.139', port=59528): Max retries exceeded with url: /zc?action=getInfo&version=2.7.1 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa788748140>: Failed to establish a new connection: [Errno 111] Connection refused'))
2024-12-31 09:57:17.318 DEBUG (MainThread) [custom_components.spotifyplus] Processing service call 'player_transfer_playback' in async 'service_handle_spotify_command' method
2024-12-31 09:57:17.319 DEBUG (MainThread) [custom_components.spotifyplus] Entity id value of 'media_player.spotifyplus_quizzical' was resolved to MediaPlayerEntity instance for the 'player_transfer_playback' method call
2024-12-31 09:57:17.319 DEBUG (MainThread) [custom_components.spotifyplus] Executing 'player_transfer_playback' service on media player 'SpotifyPlus quizzical'
2024-12-31 09:57:17.322 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Getting Spotify Connect Player state
2024-12-31 09:57:17.322 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Currently selected Source: 'Bathroom'
2024-12-31 09:57:17.421 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Transferring playback from source device name: 'Galaxy A54 5G' (id=71948c035bb6c1490496832696428994aa384373)
2024-12-31 09:57:19.777 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Transferring playback to target device name: 'Bathroom (4bbb98e5f1f833de7e7efb6d56ee3d2cddc7571d)'
2024-12-31 09:57:24.837 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Getting Spotify Connect Player state
2024-12-31 09:57:24.837 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Currently selected Source: 'Bathroom'
2024-12-31 09:57:24.918 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Selected source was changed to: 'Bathroom'
2024-12-31 09:57:24.918 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': About to resume play; last known media content: ContextUri=None, Uri=None, Position=0
2024-12-31 09:57:24.918 DEBUG (SyncWorker_8) [custom_components.spotifyplus] 'SpotifyPlus quizzical': Processed a transfer playback command - forcing a playerState scan window for the next 5 updates

Diagnostics dump

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 33 (19 by maintainers)

Most upvoted comments

Well if we’re being honest, I was surprised that you’re being so proactive in solving a problem which I assume is due to a weird implementation by Denon/Heos. I am benefiting a lot from the fix so the thanks goes entirely to you!

I have indeed disabled smartinspect. I did add in the file a comment: ; This enables advanced logging for the SpotifyPlus HACS integration for debugging purposes ; https://github.com/thlucas1/homeassistantcomponent_spotifyplus/wiki/SmartInspect-Logging-Configuration

As otherwise in a few years time I might have no clue what purpose the file serves. Unless the config file is also used for other purposes, you could consider renaming the file to SpotifyPlusSmartInspect.cfg or something like that 😃

Sorry I notice I didn’t answer your question. The scenario I’m testing at the moment doesn’t do a transfer of the playback. I just connect with a different spotify account to the device, and then do spotifyplus.get_spotify_connect_device to get back access to the device. The first time it fails, the second time it succeeds.