### System Health details
## System Information
version | core-2026.7.2
-- | -…-
installation_type | Home Assistant OS
dev | false
hassio | true
docker | true
container_arch | aarch64
user | root
virtualenv | false
python_version | 3.14.6
os_name | Linux
os_version | 6.18.34-haos-raspi
arch | aarch64
timezone | America/Chicago
config_dir | /config
<details><summary>Home Assistant Cloud</summary>
logged_in | true
-- | --
subscription_expiration | May 16, 2027 at 7:00 PM
relayer_connected | true
relayer_region | us-east-1
remote_enabled | true
remote_connected | true
remote_server | us-east-1-20.ui.nabu.casa
alexa_enabled | true
google_enabled | false
cloud_ice_servers_enabled | true
certificate_status | ready
instance_id | fe02fc040db44e4b823798f70ef238d1
iot_state | connected
iot_tries | 0
certificate_expire_date | September 24, 2026 at 2:13 PM
certificate_fingerprint | ac060d7feb419f2c2bd3112d58cee123f3e7a6af
certificate_alternative_names | undefined
can_reach_cert_server | ok
can_reach_cloud_auth | ok
can_reach_cloud | ok
</details>
<details><summary>HACS</summary>
GitHub API | ok
-- | --
GitHub Content | ok
GitHub Web | ok
HACS Data | ok
GitHub API Calls Remaining | 5000
Installed Version | 2.0.5
Stage | running
Available Repositories | 3513
Downloaded Repositories | 7
</details>
<details><summary>Home Assistant Supervisor</summary>
host_os | Home Assistant OS 18.1
-- | --
update_channel | stable
supervisor_version | supervisor-2026.07.3
agent_version | 1.9.0
docker_version | 29.5.3
disk_total | 916.2 GB
disk_used | 22.3 GB
nameservers | 192.168.1.1
healthy | true
supported | true
host_connectivity | true
supervisor_connectivity | true
ntp_synchronized | true
virtualization |
board | rpi5-64
disk_life_time | 0 %
supervisor_api | ok
version_api | ok
installed_addons | Matter Server (9.1.0), Mosquitto broker (7.1.0), Music Assistant (2.9.9), File editor (6.0.0), Speech-to-Phrase (1.4.3), Z-Wave JS (1.5.0), Terminal & SSH (10.3.0), Network UPS Tools (0.18.0), Studio Code Server (6.0.1), Piper (2.3.1), ESPHome Device Builder (2026.7.0)
</details>
<details><summary>Dashboards</summary>
dashboards | 5
-- | --
resources | 4
views | 3
mode | storage
</details>
<details><summary>Network Configuration</summary>
adapters | lo (disabled), end0 (enabled, default, auto), hassio (disabled), docker0 (disabled), veth94296ac (disabled), vethd8ab514 (disabled), vethe3dcdf3 (disabled), veth2e381d8 (disabled), veth14ac1fe (disabled), veth5f78d01 (disabled), veth48b2482 (disabled), veth89d153a (disabled), veth33e5155 (disabled), vethe678c99 (disabled), vethbf2e83a (disabled)
-- | --
ipv4_addresses | lo (127.0.0.1/8), end0 (192.168.1.106/24), hassio (172.30.32.1/23), docker0 (172.30.232.1/23), veth94296ac (), vethd8ab514 (), vethe3dcdf3 (), veth2e381d8 (), veth14ac1fe (), veth5f78d01 (), veth48b2482 (), veth89d153a (), veth33e5155 (), vethe678c99 (), vethbf2e83a ()
ipv6_addresses | lo (::1/128), end0 (fe80::c0cb:2d10:ad44:914b/64), hassio (fd0c:ac1e:2100::1/48, fe80::8412:80ff:fea4:f8f2/64), docker0 (fd84:268d:9478::1/64, fe80::101e:e1ff:fe3f:fe18/64), veth94296ac (fe80::18b2:eeff:fe6b:f04e/64), vethd8ab514 (fe80::146b:52ff:fe85:dec5/64), vethe3dcdf3 (fe80::ac85:6cff:fe89:eb5a/64), veth2e381d8 (fe80::b8a4:c6ff:feaf:fbea/64), veth14ac1fe (fe80::acdd:aaff:fef3:9223/64), veth5f78d01 (fe80::d8e7:a2ff:fea7:162/64), veth48b2482 (fe80::b854:4aff:fe6c:11be/64), veth89d153a (fe80::b87e:e6ff:fe98:973f/64), veth33e5155 (fe80::88ca:b1ff:fe77:d75/64), vethe678c99 (fe80::98a8:d3ff:fece:bc15/64), vethbf2e83a (fe80::c4b1:a3ff:fe0f:f816/64)
announce_addresses | 192.168.1.106, fe80::c0cb:2d10:ad44:914b
</details>
<details><summary>Recorder</summary>
oldest_recorder_run | July 10, 2026 at 9:44 PM
-- | --
current_recorder_run | July 21, 2026 at 9:14 AM
estimated_db_size | 257.40 MiB
database_engine | sqlite
database_version | 3.53.2
</details>
<details><summary>SpotifyPlus</summary>
integration_version | v1.0.201
-- | --
clients_configured | 1: pacowan52 (premium)
api_endpoint_reachable | ok
</details>
### Checklist
- [x] I have filled out the issue template to the best of my ability.
- [x] This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
- [x] This issue is not a duplicate report ([search previously reported issues](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/issues?q=is%3Aissue+label%3Abug)).
### Describe the issue
## Summary
Intermittent authorization failures when controlling playback (e.g. pressing "Next Track" on the SpotifyPlus media player card, or issuing `media_player`/`spotifyplus` service calls from automations/pyscript). The failing call is not the playback command itself — it appears to originate from a background "Spotify Connect Directory Task" trying to refresh the dynamic device list via `GetPlayerPlaybackState`.
## Environment
- SpotifyPlus version: Version v1.0.201
- Home Assistant Core version: 2026.7.2
- Installation method: Home Assistant OS/Supervised
- Spotify account: Premium (active subscription, not free tier)
- Media player affected: WiiM Pro (`media_player.wiim_pro_player`) via Spotify Connect
## Observed Error
Exact text captured from the SpotifyPlus media player card:
```
Control action failed: Spotify Connect Directory Task - Could not retrieve dynamic device list: SAM1001E - Spotify Web API returned an error status while processing the "GetPlayerPlaybackState" method. Status: 401 - Unauthorized Message: "Access token missing"
```
A second, differently-worded error ("Premium account required") is also seen intermittently for the same underlying action, despite the account being an active Premium subscription. This suggests "Premium account required" may be a misleading surface message for the same underlying auth-attachment failure rather than a real permissions issue.
## What I've Ruled Out
- **Not a Premium/permissions issue** — account is Premium, and the official Spotify desktop app works without issue at the same time.
- **Not (solely) a stale-credentials issue** — uninstalled and reinstalled the SpotifyPlus integration with fresh OAuth credentials; the intermittent errors continued afterward.
- **Not specific to the Lovelace card** — the same intermittent auth failures occur when calling SpotifyPlus/media_player services directly from Home Assistant automations/pyscript, not just from the UI card.
## Suspected Cause
The error text says "Access token missing" rather than "access token expired" — these read like distinct strings from Spotify's API. "Missing" suggests the outgoing request may have gone out with no Authorization header attached at all, rather than with a stale/expired one. Combined with:
- the failure occurring on a background "Spotify Connect Directory Task" rather than the user-initiated command itself, and
- an immediate retry usually succeeding, with no need to wait out a token expiry/refresh window,
this looks more like a race condition in when/how the access token gets attached to outgoing requests for this specific background device-list-refresh task, rather than a genuinely expired/invalid token or a Spotify-side outage.
### Reproduction steps
1. Use the SpotifyPlus media player card (or call a `spotifyplus.*`/`media_player.*` service from an automation or pyscript) to control playback — e.g. skip to next track.
2. Intermittently (not on every attempt) the action fails with an error banner instead of executing.
3. Retrying the same action — usually immediately, sometimes needs 2+ attempts — succeeds.
### Debug logs
```text
[14:12:18] INFO: Home Assistant Core finish process exit code 0
[14:12:18] INFO: Home Assistant Core service shutdown
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: warning: service s6rc-oneshot-runner is marked as essential, not stopping it
s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun home-assistant (no readiness notification)
s6-rc: info: service legacy-services successfully started
2026-07-21 09:14:33.895 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration spotifyplus which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-07-21 09:14:33.896 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-07-21 09:14:33.897 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration alexa_media which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-07-21 09:14:33.898 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration pyscript which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-07-21 09:14:33.898 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration enhanced_input which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-07-21 09:14:33.899 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration sofabaton_x1s which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2026-07-21 09:14:40.107 WARNING (MainThread) [aioasuswrt.asuswrt] async_get_bytes_total is deprecated, calculate this elsewhere
2026-07-21 09:14:40.194 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/music_helpers.py
2026-07-21 09:14:40.203 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/players.py
2026-07-21 09:14:40.229 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/music_lookup.py
2026-07-21 09:14:40.240 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/build_lastfm_lms_radio_playlist.py
2026-07-21 09:14:40.242 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/shopping_list.py
2026-07-21 09:14:40.249 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/movie_lookup.py
2026-07-21 09:14:40.266 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/cloud_activity.py
2026-07-21 09:14:41.550 ERROR (MainThread) [music_assistant_client.connection] Failed to connect to ws://d5369777-music-assistant:8094/ws: Cannot connect to host d5369777-music-assistant:8094 ssl:False [Timeout while contacting DNS servers]
2026-07-21 09:14:44.028 ERROR (MainThread) [homeassistant.components.esphome.coordinator] Error requesting ESPHome Dashboard data: Cannot connect to host 127.0.0.1:62035 ssl:default [Connect call failed ('127.0.0.1', 62035)]
2026-07-21 09:14:44.028 ERROR (MainThread) [homeassistant.components.esphome.dashboard] Dashboard unavailable; skipping reauth: Cannot connect to host 127.0.0.1:62035 ssl:default [Connect call failed ('127.0.0.1', 62035)]
2026-07-21 09:14:48.240 WARNING (zeroconf-ServiceBrowser-_googlecast._tcp-127) [pychromecast.dial] Failed to determine cast type for host <unknown> (<urlopen error [Errno 111] Connection refused>) (services:{MDNSServiceInfo(name='QN90F-d20f51819516efe11b9705719b49b631._googlecast._tcp.local.')})
2026-07-21 09:14:48.980 WARNING (zeroconf-ServiceBrowser-_googlecast._tcp-133) [pychromecast.dial] Failed to determine cast type for host <unknown> (<urlopen error [Errno 111] Connection refused>) (services:{MDNSServiceInfo(name='QN90F-d20f51819516efe11b9705719b49b631._googlecast._tcp.local.')})
2026-07-21 09:14:51.251 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to import_module with args ('custom_components.spotifyplus.intent',) in /usr/src/homeassistant/homeassistant/loader.py, line 1321: return importlib.import_module(f"{self.pkg_path}.{platform_name}") inside the event loop; This is causing stability issues. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#import_module
Traceback (most recent call last):
File "<frozen runpy>", line 203, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module>
sys.exit(main())
File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main
exit_code = runner.run(runtime_conf)
File "/usr/src/homeassistant/homeassistant/runner.py", line 289, in run
return loop.run_until_complete(setup_and_run_hass(runtime_config))
File "/usr/local/lib/python3.14/asyncio/base_events.py", line 706, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.14/asyncio/base_events.py", line 677, in run_forever
self._run_once()
File "/usr/local/lib/python3.14/asyncio/base_events.py", line 2056, in _run_once
handle._run()
File "/usr/local/lib/python3.14/asyncio/events.py", line 94, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 106, in _async_process_integration_platforms_for_component
platforms = await integration.async_get_platforms(platforms_that_exist)
File "/usr/src/homeassistant/homeassistant/loader.py", line 1190, in async_get_platforms
platforms.update(self._load_platforms(platform_names))
File "/usr/src/homeassistant/homeassistant/loader.py", line 1114, in _load_platforms
platform_name: self._load_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 1289, in _load_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 1321, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
2026-07-21 09:14:51.641 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for esp32-s3-box-3-d650a4 @ 192.168.1.185: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.185', port=6053))]: [Errno 113] Connect call failed ('192.168.1.185', 6053) (SocketAPIError)
2026-07-21 09:14:51.642 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for respeaker-xvf3800-assistant @ 192.168.1.82: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.82', port=6053))]: [Errno 113] Connect call failed ('192.168.1.82', 6053) (SocketAPIError)
2026-07-21 09:14:51.643 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for atom-echos3r-0ee758 @ 192.168.1.87: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.87', port=6053))]: [Errno 113] Connect call failed ('192.168.1.87', 6053) (SocketAPIError)
2026-07-21 09:15:00.818 ERROR (MainThread) [music_assistant_client.connection] Failed to connect to ws://d5369777-music-assistant:8094/ws: Cannot connect to host d5369777-music-assistant:8094 ssl:False [Timeout while contacting DNS servers]
2026-07-21 09:16:27.360 WARNING (MainThread) [homeassistant.components.media_player] Updating spotifyplus media_player took longer than the scheduled update interval 0:00:01
2026-07-21 09:16:32.363 WARNING (MainThread) [homeassistant.components.media_player] Updating spotifyplus media_player took longer than the scheduled update interval 0:00:01
2026-07-21 09:16:34.476 ERROR (SyncWorker_29) [custom_components.spotifyplus] SpotifyApiError: Spotify Connect Directory Task - Could not retrieve dynamic device list: SAM1001E - Spotify Web API returned an error status while processing the "GetPlayerPlaybackState" method.
Status: 401 - Unauthorized
Message: "Access token missing"
Traceback (most recent call last):
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyconnect/spotifyconnectdirectorytask.py", line 1468, in RefreshDynamicDevices
scDevice:SpotifyConnectDevice = self.UpdateActiveDevice()
~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyconnect/spotifyconnectdirectorytask.py", line 1733, in UpdateActiveDevice
playerState:PlayerPlayState = self._SpotifyClientInstance.GetPlayerPlaybackState(additionalTypes=SpotifyMediaTypes.EPISODE.value)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyclient.py", line 8841, in GetPlayerPlaybackState
self.MakeRequest('GET', msg)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyclient.py", line 1598, in MakeRequest
msg.ResponseData = self._CheckResponseForErrors(msg, response)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyclient.py", line 842, in _CheckResponseForErrors
raise SpotifyWebApiError(errCode, errMessage, msg.MethodName, response.reason, _logsi)
spotifywebapipython.spotifywebapierror.SpotifyWebApiError: SAM1001E - Spotify Web API returned an error status while processing the "GetPlayerPlaybackState" method.
Status: 401 - Unauthorized
Message: "Access token missing"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/spotifyplus/media_player.py", line 1273, in update
self._playerState = self.data.spotifyClient.GetDevicePlaybackState(deviceId=self._attr_source)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyclient.py", line 6978, in GetDevicePlaybackState
scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, activateDevice=False)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyclient.py", line 1109, in _ResolveDeviceObject
scDevice = self.GetSpotifyConnectDevice(
device,
refreshDeviceList=True,
activateDevice=activateDevice)
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyclient.py", line 10877, in GetSpotifyConnectDevice
scDevice = self._SpotifyConnectDirectory.GetDevice(deviceValue, refreshDynamicDevices=True, raiseExceptionIfNotFound=False)
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyconnect/spotifyconnectdirectorytask.py", line 1132, in GetDevice
scActiveDevice = self.RefreshDynamicDevices()
File "/usr/local/lib/python3.14/site-packages/spotifywebapipython/spotifyconnect/spotifyconnectdirectorytask.py", line 1485, in RefreshDynamicDevices
raise SpotifyApiError("%s - Could not retrieve dynamic device list: %s" % (self.name, str(ex)), ex, logsi=_logsi)
spotifywebapipython.spotifyapierror.SpotifyApiError: SpotifyApiError: Spotify Connect Directory Task - Could not retrieve dynamic device list: SAM1001E - Spotify Web API returned an error status while processing the "GetPlayerPlaybackState" method.
Status: 401 - Unauthorized
Message: "Access token missing"
2026-07-21 09:16:34.502 ERROR (MainThread) [homeassistant.helpers.entity] Update for media_player.spotifyplus_pacowan52 fails
```
### Diagnostics dump
## Questions for the maintainer
- Does the "Spotify Connect Directory Task" run on its own schedule/thread separate from the main token refresh logic? Could there be a window where it fires before a refresh completes, or after the token is cleared but before it's repopulated?
- Is there a debug logging flag that would help confirm this is a token-attachment timing issue rather than something Spotify-side?
Happy to provide debug logs, exact version numbers, and to test a patched build if that's useful.