Spotify plugin for Homebridge written in Rust. The plugin requires a Spotify Premium account.
sudo npm install -g homebridge
sudo npm install -g homebridge-rusty-spotify
http://localhost/callback
as "Redirect URI" and saveThe generate_config
script can be used to generate the config. It requires for the client_id
, client_secret
and
Spotify username
needs to be set since those are required to authenticate to the Spotify Web API. To run the script,
make sure to have Python 3 and the spotipy
library installed.
Running the script will open a web browser asking to authenticate to Spotify which is required to retrieve the refresh_token
.
$ ./generate_config --help
usage: generate_config [-h] [--client_id CLIENT_ID]
[--client_secret CLIENT_SECRET]
[--redirect_uri REDIRECT_URI] [--username USERNAME]
Script to retrieve an access and refresh token for using the Spotify API
optional arguments:
-h, --help show this help message and exit
--client_id CLIENT_ID, --client-id CLIENT_ID
Spotify client ID
--client_secret CLIENT_SECRET, --client-secret CLIENT_SECRET
Spotify client secret
--redirect_uri REDIRECT_URI, --redirect-uri REDIRECT_URI
Redirect URI
--username USERNAME Spotify username
$ ./generate_config --client_id=<client_id> --client_secret=<client_secret> --username=<username>
{
"platform": "Spotify",
"name": "Spotify",
"service_type": "light", // "light" or "speaker"; Speaker is not supported by HomeKit
"client_id": "<client_id>",
"client_secret": "<client_secret>",
"refresh_token": "<refresh_token>"
}
The generated config needs to copied to the Homebridge config file (e.g. ~/.homebridge/config.json
). For example:
//...
"platforms": [
{
"platform": "Spotify",
"name": "Spotify",
"service_type": "light", // "light" or "speaker"; Speaker is not supported by HomeKit
"client_id": "<client_id>",
"client_secret": "<client_secret>",
"refresh_token": "<refresh_token>",
}
]
//...
service_type
specifies whether Spotify devices should use the Lightbulb
or Speaker service. If service_type
is not specified, "light"
will be used by default.
HomeKit currently does not support Speaker services and will show "This accessory is not certified and may not work reliably with HomeKit".
Add the plugin in the Home app. The plugin will automatically discover available Spotify devices and add them as accessories. Turning a Spotify accessory on will resume playing music on the device, turning off the accessory will pause the music. The accessory also allows to change the playback volume.
Accessories get refreshed every 10 seconds (or as specified in the configuration file).
wasm-pack
, cargo-generate
and npm
by following this guidemake
pkg/
directory containing all the generated nodejs filesnpm install
to install all required dependenciesDEBUG=* homebridge -D -P /path/to/plugin/homebridge-rusty-spotify
A blog post about writing plugins for Homebridge and specifically this plugin has been published here.