Spotify
The Spotify media player integration lets you control your Spotify
account playback and browse the Spotify
Prerequisites
- An active Spotify account. A premium account is not required, but recommended. Premium accounts can be controlled (pause, play, next, etc.), while free accounts can only be used for browsing and current playback status.
- Spotify compatible playback source device
- A Spotify Developer application. Instructions for that are in the next step.
Create a Spotify application
For Home Assistant to communicate with Spotify, we need to create an application at Spotify using the Spotify Developer website. This will provide you with the Spotify application credentials Home Assistant needs to allow you to log in with your Spotify account.
-
If Spotify was previously integrated with your Home Assistant with outdated credentials, it might be required to remove these old Spotify account credentials using the Home Assistant Application Credentials dashboard.
-
Log in to the Spotify Developer Dashboard
. -
Select the Create app
button in the top right.
-
Enter a name and description; feel free to use any name and description you like.
Set the “Redirect URI” to the following:
https://my.home-assistant.io/redirect/oauth
Please copy and paste the exact URL above. You do not have to change it.
-
Select Web API.
-
Check the box to agree with the requirements and click the Save button to confirm the application creation.
-
Spotify will now show the new application you have just created. Select the Settings button in the top right to configure it.
- Before we can start configuring Home Assistant, we need to grab the application credentials Home Assistant needs.
Select on the View client secret button to reveal the client secret.
- The “Client ID” and “Client secret” are the two pieces of information that Home Assistant needs to communicate with Spotify and is what we call: Application credentials.
You will need the “Client ID” and “Client secret” during the Spotify integration setup process in Home Assistant.
You can now continue with the next chapter to configure the Spotify integration in Home Assistant.
I have manually disabled My Home Assistant
If you don’t have My Home Assistant on your installation,
you can use <HOME_ASSISTANT_URL>/auth/external/callback
as the redirect URI
instead.
The <HOME_ASSISTANT_URL>
must be the same as used during the configuration/
authentication process.
Internal examples: http://192.168.0.2:8123/auth/external/callback
, http://homeassistant.local:8123/auth/external/callback
.”
Configuration
To add the Spotify service to your Home Assistant instance, use this My button:
Spotify can be auto-discovered by Home Assistant. If an instance was found, it will be shown as Discovered. You can then set it up right away.
Manual configuration steps
If it wasn’t discovered automatically, don’t worry! You can set up a manual integration entry:
-
Browse to your Home Assistant instance.
-
In the bottom right corner, select the
Add Integration button. -
From the list, select Spotify.
-
Follow the instructions on screen to complete the setup.
Using multiple Spotify accounts
This integration supports multiple Spotify accounts at once. You don’t need to create another Spotify application in the Spotify Developer Portal. Multiple Spotify accounts can be linked to a single Spotify application.
You will have to add those accounts into the User Management section of your application in the Spotify Developer Portal.
To add an additional Spotify account to Home Assistant, go to the Spotify website, log out, and then repeat only the steps in the Configuration section.
Selecting output source
To play media Spotify first needs a device selected for audio output known as the source
.
# Example code to select an AV receiver as the output device
action: media_player.select_source
target:
entity_id: media_player.spotify
data:
source: "Denon AVR-X2000"
The Spotify API cannot initiate playback to a device not already known to the Spotify API. The source list of available devices can be found in the Details section of the Spotify Media Player Control and the source_list
attribute in the Developer Tools States.
Playing Spotify playlists
You can send playlists to Spotify using the "media_content_type": "playlist"
, which is part of the
media_player.play_media action, for example:
# Example script to play playlist
script:
play_jazz_guitar:
sequence:
- action: media_player.play_media
target:
entity_id: media_player.spotify
data:
media_content_id: "https://open.spotify.com/playlist/5xddIVAtLrZKtt4YGLM1SQ?si=YcvRqaKNTxOi043Qn4LYkg"
media_content_type: playlist
The media_content_id
value can be obtained from the Spotify desktop app by clicking on the more options (”…”) next to the album art picture, selecting “Share” and then “Copy Spotify URI” or “Copy Playlist Link” (also available in the Spotify phone and web app). Alternatively a Spotify URI string (e.g. spotify:playlist:5xddIVAtLrZKtt4YGLM1SQ
) can be supplied for the media_content_id
.
Unsupported devices
- Sonos: Although Sonos is a Spotify Connect device, it is not supported by the official Spotify API.
Sensors
Spotify provides sensors that display information about the song that is currently being played. The following sensors are available:
- Song acousticness: Indicates how much the sound is free from electronic modification. 100% indicates it not electronically modified.
- Song danceability. In percent. Describes how suitable a track is for dancing based on a combination of musical elements including tempo, rhythm stability, beat strength, and overall regularity. The higher the value, the more danceable.
- Song energy. In percent. A measure of intensity and activity. Typically, energetic tracks feel fast, loud, and noisy. For example, death metal has high energy, while a Bach prelude scores low on the scale. Perceptual features contributing to this attribute include dynamic range, perceived loudness, timbre, onset rate, and general entropy. A higher number means more energetic.
- Song instrumentalness: In percent. Describes whether a track contains no vocals. “Ooh” and “aah” sounds are treated as instrumental in this context. Rap or spoken word tracks are clearly “vocal”. The higher the value the more instrumental the song is.
- Song key: The estimated overall key of the track. If no key was detected, the value is unknown. For example, C sharp or E flat.
- Song liveness: In percent. Describes the presence of an audience in the recording. Higher liveness values represent an increased probability that the track was performed live.
- Song mode: The modality (major or minor) of a song.
- Song speechiness: In percent. Describes the presence of spoken words in a song. The more exclusively speech-like the recording (for example, talk show, audio book, poetry), the higher the value.
- Song tempo: The speed of the piece of music that is currently playing, in beats per minute (bpm).
- Song time signature: The time signature (meter) is a notational convention to specify how many beats are in each bar (or measure). For example: 4/4, 6/8.
- Song valence. In percent. Tracks with high valence sound more positive (happy, cheerful, euphoric), while tracks with low valence sound more negative (sad, depressed, angry).