{"id":13580160,"url":"https://github.com/fondberg/spotcast","last_synced_at":"2025-12-28T23:44:40.802Z","repository":{"id":36229992,"uuid":"183212377","full_name":"fondberg/spotcast","owner":"fondberg","description":"Home assistant custom component to start Spotify playback on an idle chromecast device as well as control spotify connect devices","archived":false,"fork":false,"pushed_at":"2025-05-08T10:35:13.000Z","size":3071,"stargazers_count":753,"open_issues_count":24,"forks_count":105,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-08T11:39:16.415Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fondberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["fondberg","fcusson"]}},"created_at":"2019-04-24T11:11:28.000Z","updated_at":"2025-05-08T10:35:16.000Z","dependencies_parsed_at":"2024-03-01T14:29:01.138Z","dependency_job_id":"234bb149-5eeb-4e66-b649-c730d94e411f","html_url":"https://github.com/fondberg/spotcast","commit_stats":null,"previous_names":[],"tags_count":119,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fondberg%2Fspotcast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fondberg%2Fspotcast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fondberg%2Fspotcast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fondberg%2Fspotcast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fondberg","download_url":"https://codeload.github.com/fondberg/spotcast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249206,"owners_count":22039029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:01:48.178Z","updated_at":"2025-12-28T23:44:40.762Z","avatar_url":"https://github.com/fondberg.png","language":"Python","funding_links":["https://github.com/sponsors/fondberg","https://github.com/sponsors/fcusson"],"categories":["Install from Source","Python","Custom Integrations"],"sub_categories":["Smart Home Automation","Alternative Dashboards"],"readme":"# Spotcast\n\n[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/hacs/integration)\n[![spotcast](https://img.shields.io/github/release/fondberg/spotcast.svg?1)](https://github.com/fondberg/spotcast)\n![Maintenance](https://img.shields.io/maintenance/yes/2025.svg)\n\nHome Assistant custom component to start Spotify playback on an idle chromecast device or a Spotify Connect device (thanks to @kleinc80) which means that you can target your automation for chromecast as well as connect devices.\n\nSpotcast implements a cast platform (requires Home Assistant Core 2022.2.0 or later), which enables Google Cast media player entities to play Spotify URI as well as to browse the Spotify library.\n\nThis component is not meant to be a full Spotify chromecast media_player but only serves to start the playback. Controlling the chromecast device and the Spotify playback after the initial start is done in their respective components.\nBecause starting playback using the API requires more powerful token the username and password used for browser login is used.\n\n\u003e [!WARNING]\n\u003e A breaking change in Home Assitant `2024.11` is causing [Spotify-Card](https://github.com/custom-cards/spotify-card) to break. As the project has no active maintainer, this break cannot be fixed, but a fork of the project can be found [here](https://github.com/mikevanes/spotify-card-v2). If you are having issue with [Spotify-Card-V2](https://github.com/mikevanes/spotify-card-v2) make sure bto open a ticket in that repository. This projects and its maintainers do not manage the other project and cannot help you directly.\n\nUsed by [Spotify-Card-V2](https://github.com/mikevanes/spotify-card-v2)\n\n__[Community post](https://community.home-assistant.io/t/spotcast-custom-component-to-start-playback-on-an-idle-chromecast-device/114232)__\n\n## Installation\n\n### HACS\n\nThis component is easiest installed using [HACS](https://github.com/custom-components/hacs).\n\n### Manual installation\n\nCopy all files from custom_components/spotcast/ to custom_components/spotcast/ inside your config Home Assistant directory.\n\n## Configuration\n\n### Minimum Home Assistant version\n\nSpotcast is compatible with any version since 2024.11.0.\n\n### Official Spotify Integration\n\nNote that as of v3.5.2 you must also have the official [Home Assistant Spotify Integration](https://www.home-assistant.io/integrations/spotify/) installed and configured for this custom component to work. This is because it provides the correct device list which has the correct scopes in its token.\n\n### Obtaining `sp_dc` and `sp_key` cookies\n\nSpotcast uses two cookies to authenticate against Spotify in order to have access to the required services.\n\nTo obtain the cookies, these different methods can be used:\n\n#### Chrome based browser\n\n##### Chrome web console\n\n1. Open a new __Incognito window__ at [`https://open.spotify.com`](https://open.spotify.com) and login to Spotify.\n2. Press `Command+Option+I` (Mac) or `Control+Shift+I` or `F12`. This should open the developer tools menu of your browser.\n3. Go into the `application` section.\n4. In the menu on the left go int `Storage/Cookies/open.spotify.com`.\n5. Find the `sp_dc` and `sp_key` and copy the values.\n6. Close the window without logging out (Otherwise the cookies are made invalid).\n\n![cookie in chrome developer tools](images/cookies_chrome_2.png)\n\n#### Firefox based browser\n\n##### Firefox web console\n\n1. Open a new __Incognito window__ at [`https://open.spotify.com`](https://open.spotify.com) and login to Spotify.\n2. Press `Command+Option+I` (Mac) or `Control+Shift+I` or `F12`. This should open the developer tools menu of your browser.\n3. Go into the `Storage` section. (You might have to click on the right arrows to reveal the section).\n4. Select the `Cookies` sub-menu and then `https://open.spotify.com`.\n5. Find the `sp_dc` and `sp_key` and copy the values.\n6. Close the window without logging out (Otherwise the cookies are made invalid).\n\n![Firefox developer tool](images/cookies_firefox_1.png)\n\n### Single account\n\nAdd the following to your configuration.yaml:\n\n```yaml\nspotcast:\n  sp_dc: !secret sp_dc\n  sp_key: !secret sp_key\n  country: SE #optional, added in 3.6.24\n```\n\n### Multiple accounts\n\nAdd `accounts` dict to the configuration and populate with a list of accounts to\nbe able to initiate playback using diffferent accounts than the default.\n\nIf you are using v3.5.2 or greater and thus also have the core Spotify Integration installed, then [the additional accounts will also need to be added there as well](https://www.home-assistant.io/integrations/spotify#using-multiple-spotify-accounts) for multiple accounts to work.\n\n```yaml\nspotcast:\n  sp_dc: !secret primary_sp_dc\n  sp_key: !secret primary_sp_key\n  country: SE #optional, added in 3.6.24\n  accounts:\n    niklas:\n      sp_dc: !secret niklas_sp_dc\n      sp_key: !secret niklas_sp_key\n    ming:\n      sp_dc: !secret ming_sp_dc\n      sp_key: !secret ming_sp_key\n```\n\n### Edit secrets.yaml\n\nPlease note: configuration.yaml is a plain text file and [it is not recommended to store your passwords in this file](https://www.home-assistant.io/docs/configuration/secrets/).\n\nBy using the ```!secret``` tag you are directing Home Assistant to look inside the secrets.yaml file for your key instead.\n\nFor a single account add the following to your secrets.yaml file:\n\n```yaml\nsp_dc: [your sp_dc here]\nsp_key: [your sp_key here]\n```\n\nFor multiple accounts add the corresponding entries to your secrets.yaml file. For example, using the same accounts as above:\n\n```yaml\nprimary_sp_dc: [your sp_dc here]\nprimary_sp_key: [your sp_key here]\nniklas_sp_dc: [niklas sp_dc here]\nniklas_sp_key: [niklas sp_key here]\nming_sp_dc: [ming sp_dc here]\nming_sp_key: [ming sp_key here]\n```\n\n## Call the service\n\nThe spotcast custom component creates a service called 'spotcast.start' in Home Assistant.\n\n### Start playback on Spotify connect device\n\n```yaml\n- service: spotcast.start\n  data:\n    spotify_device_id: \"ab123c5d7347324c2b1234567890f8d6dc40350\"\n    uri: \"spotify:playlist:5xddIVAtLrZKtt4YGLM1SQ\"\n    random_song: true\n```\n\n### Start playback on a device with default account\n\n```yaml\n- service: spotcast.start\n  data:\n    device_name: \"Kitchen\"\n    uri: \"spotify:playlist:5xddIVAtLrZKtt4YGLM1SQ\"\n    random_song: true\n```\n\nwhere:\n\n* `spotify_device_id` is the device ID of the Spotify Connect device\n* `device_name` is the friendly name of the chromecast device\n* `uri` is the Spotify uri, supports all uris including track (limit to one track)\n* `search` is a search query to resolve into a uri. This parameter will be overlooked if a uri is provided\n* `category` let spotify pick a random playlist inside a given [category](https://developer.spotify.com/console/get-browse-categories/)\n* `country` restrict country to use when looking for playlists inside a category\n* `limit` restrict number of playlists to return when looking in a category. Note that only a single playlist will be chosen randomly from them.\n* `random_song` optional parameter that starts the playback at a random position in the playlist\n* `repeat` optional parameter that repeats the playlist/track (track|context|off)\n* `shuffle` optional parameter to set shuffle mode for playback\n* `offset` optional parameter to set offset mode for playback. 0 is the first song\n\nOptionally you can specify the `entity_id` of an existing Home Assistant chromecast media-player like:\n\n```yaml\n- service: spotcast.start\n  data:\n    entity_id: \"media_player.vardagsrum\"\n    uri: \"spotify:playlist:5xddIVAtLrZKtt4YGLM1SQ\"\n```\n\n### Find Spotify Device ID\n\nTo use the Spotcast service with a Spotify Connect device, you need the `spotify_device_id`. To find the `spotify_device_id`, multiple option are available.\n\n#### With Spotify developer portal\n\n1. Go to [Spotify developer console](https://developer.spotify.com/console/get-users-available-devices/)\n2. Click `TRY IT` \u003cbr/\u003e\n3. Extract the ID (there could be more than one if you have more than one speaker) from the 'RESPONSE SAMPLE' on the right\n\n#### Through Spotcast log\n\n1. Enable the debug logs (instructions are in section `Enabling Debug Log` in this README)\n2. Reboot Home Assistant\n3. Go to `Configuration \u003e\u003e Logs \u003e\u003e Load Full Home Assistant Log`.\n4. For chromecast devices, make sure to play media on the device prior to checking the logs as they will not show unless active\n5. Find the log entry `get_spotify_devices` and look for the device ID.\n\n#### Sonos Device ID\n\n1. Open the Spotify Web Player and sign in if needed\n2. Make sure you see your Sonos devices in the Connect popup\n3. Open your browser's DevTools (F12 for Chrome)\n4. Navigate to the Network tab\n5. Connect to the desired Sonos device in the Web Player\n6. Find the associated request in your DevTools\n7. The request URL looks something like this: `https://gew1-spclient.spotify.com/connect-state/v1/connect/transfer/from/my_web_player_device_id/to/my_sonos_device_id`\n8. The `my_sonos_device_id` is the `spotify_device_id` you are looking for.\n\n##### Log example\n\n```LOG\n2022-01-13 19:10:35 DEBUG (SyncWorker_0) [custom_components.spotcast.helpers] get_spotify_devices: media_player.spotify_felix: Spotify Félix Cusson: [{'id': '################################', 'is_active': True, 'is_private_session': False, 'is_restricted': False, 'name': 'Salon', 'type': 'CastAudio', 'volume_percent': 16}]\n2022-01-13 19:10:35 DEBUG (SyncWorker_0) [custom_components.spotcast.helpers] get_spotify_devices: {'devices': [{'id': '###############################', 'is_active': False, 'is_private_session': False, 'is_restricted': False, 'name': 'Salon', 'type': 'CastAudio', 'volume_percent': 16}]}\n\n# Look for\n\u003c...\u003e Spotify Félix Cusson: [{'id': '################################', \u003c- This is the device ID\n```\n\n### Automation example\n\n```yaml\n- id: 'christmas_play_christmas_music'\n  alias: Christmas play Christmas music\n  initial_state: 'on'\n  trigger:\n  - event_data:\n      id: remote_windowlamps\n      event: 5002\n    platform: event\n    event_type: deconz_event\n  condition: []\n  action:\n  - service: spotcast.start\n    data:\n      uri: 'spotify:playlist:56Bor5fbMJlJV7oryb2p3k'\n      random_song: true\n      shuffle: true\n      start_volume: 50\n      entity_id: media_player.kitchen\n```\n\n```yaml\n- service: spotcast.start\n  data:\n    search: \"Brown Bird\" # resolves to spotify:artist:5zzbSFZMVpvxSlWAkqqtHP at the time of writing\n    random_song: true\n    shuffle: true\n    start_volume: 50\n    entity_id: media_player.kitchen\n```\n\n### Transfer current playback for the account\n\nOmitting `uri` will transfer the playback to the specified device.\n\n```yaml\n- service: spotcast.start\n  data:\n    device_name: \"Speaker kitchen\"\n```\n\nUse the parameter `force_playback` to continue the user's playback even if nothing is currently playing.\n\n```yaml\n- service: spotcast.start\n  data:\n    device_name: \"Speaker kitchen\"\n    force_playback: true\n```\n\nwhere:\n\n* `device_name` is the friendly name of the chromecast\n* `force_playback` (optional) true or false, true to continue the user's playback even if nothing is currently playing\n\n### Start playback on a device with non default account\n\n```yaml\n- service: spotcast.start\n  data:\n    account: \"niklas\"\n    device_name: \"Speaker kitchen\"\n    uri: \"spotify:playlist:5xddIVAtLrZKtt4YGLM1SQ\"\n```\n\nwhere:\n\n* `account` is the name of account key in the accounts dictionary in the configuration\n* `device_name` is the friendly name of the chromecast\n* `uri` is the Spotify uri, supports all uris including track (limit to one track)\n\n### Start podcast playback\n\nPlay the latest episode of a given podcast show.\n\n```yaml\n- service: spotcast.start\n  data:\n    account: \"niklas\"\n    device_name: \"Speaker kitchen\"\n    uri: \"spotify:show:6PeAI9SHRZhghU7NRPXvT3\"\n    ignore_fully_played: true\n```\n\nwhere\n\n* `account` is the name of account key in the accounts dictionary in the configuration\n* `device_name` is the friendly name of the Chromecast\n* `uri` is the spotify uri, (podcasts use the 'show' uri)\n* `ignore_fully_played` (optional) true or false, true to ignore already fully played episodes (defaults to false and plays the latest released episode)\n\n## Use the sensor\n\nThe sensor has the discovered chromecasts as both json and an array of objects.\nSince v3.4.0 it does not do its own discovery but relies on data from core cast.\nAdd the following to the sensor section of the configuration:\n\n```yaml\nsensor:\n  - platform: spotcast\n    country: SE\n```\n\nThe country tag was added in v3.6.24. This tag is optional. If ommited or if you haven't updated the configuration since the update, it will default to \"SE\" (which it always did before)\n\nSensor name:\n\n```yaml\nsensor.chromecast_devices\n```\n\nAttributes\n\n```yaml\ndevices_json: [\n  {\n    \"name\": \"Speaker kitchen\",\n    \"cast_type\": \"audio\",\n    \"model_name\": \"Google Home\",\n    \"uuid\": \"xxxxx\",\n    \"manufacturer\": \"Google Inc.\"\n  },\n  {\n    \"name\": \"Speakers upstairs\",\n    \"cast_type\": \"group\",\n    \"model_name\": \"Google Cast Group\",\n    \"uuid\": \"xxxx\",\n    \"manufacturer\": \"Google Inc.\"\n  },\n  {\n    \"name\": \"Living room\",\n    \"cast_type\": \"cast\",\n    \"model_name\": \"HK Citation 300\",\n    \"uuid\": \"xxxx\",\n    \"manufacturer\":\"Harman Kardon\"\n    }\n  ]\n\nlast_update: 2019-05-01T15:27:49.828553+02:00\n\nfriendly_name: Chromecast Devices\n```\n\n## Websocket API\n\nThe components websocket api.\n\nMethod: `spotcast/playlist` supporting different `playlist_type`s.\n\n* `user`, or `default` for user chosen saved playlists\n* `featured` for spotify \"featured\" playlists (not personalized)\n* `discover-weekly` for personalized \"Made for _____\" (includes daily mixes)\n* `recently-played` for \"Recently Played\"\n* ... any other `view id` as found in the API at [https://api.spotify.com/v1/views/personalized-recommendations](https://api.spotify.com/v1/views/personalized-recommendations)\n\nExample usage:\n\n```python\n// Retrieve playlists\nconst res = await this.props.hass.callWS({\n  type: 'spotcast/playlists',\n  playlist_type: 'featured', // 'user' for saved playlists, 'featured' for spotify featured, or personalized view id\n  country_code: 'SV', // Optional country code used by featured playlists\n  limit: 20, // Optional limit, default is 10\n  account: 'ming' // optional account name\n});\n\n// Retrieve devices\nconst res = await this.props.hass.callWS({\n  type: 'spotcast/devices',\n  account: 'ming' // optional account name\n});\n\n// Retrieve player\nconst res = await this.props.hass.callWS({\n  type: 'spotcast/player',\n  account: 'ming' // optional account name\n});\n```\n\n## Enabling debug log\n\nIn configuration.yaml for you HA add and attach those the relevant logs.\nBe sure to disable it later as it is quite noisy.\n\n```yaml\nlogger:\n  default: info\n  logs:\n    custom_components.spotcast: debug\n```\n\n## Contribute\n\nPlease do! Open a Pull Request with your improvements.\n\nThis project was made possible by the original creator Niklas Fondberg. All\nyour great work are greatly appreciated.\n\n## License\n\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffondberg%2Fspotcast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffondberg%2Fspotcast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffondberg%2Fspotcast/lists"}