What I really appreciate about Spotify is the good connectivity. You can play or control music or podcasts on another device with just a few clicks.
Thanks to the free possibility of setting up developer access, many of these functions can also be accessed from NodeRed. With a few cleverly linked nodes, you can easily create your own “Spotify remote control” for (for example) the dashboard.
The control options are of course not limited to the dashboard. The control option could also be triggered, for example, via connected buttons or other options. 🙂
You can find a first approach to this in the following article.
- 1 Safety instructions
- 2 Affiliate links / advertising links
- 3 Requirements
- 4 Log in to the NodeRed configuration interface
- 5 Credits
- 6 Install the needed nodes
- 7 Activate the Spotify Developer account
- 8 Insert NodeCode
- 9 Enter account access data in NodeRed
- 10 Solution for error “INVALID_CLIENT: Invalid redirect URI”
- 11 The Spotify playback jumps or stalls sometimes
- 12 Have fun with the project
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
So that you can install new nodes, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.
- RaspberryPi – Setup for nerdiys!
- RaspberryPi – The first configuration!
- RaspberryPi – Control the RaspberryPi via SSH
- NodeRed – Installation of NodeRed on the RaspberryPi
- NodeRed – Installing new nodes
- NodeRed – Import and export node code
In the following list you will find all the parts you need to implement this article.
Log in to the NodeRed configuration interface
Before you can edit your NodeRed configuration you must - if activated - first log in to the NodeRed configuration interface.
First of all, thanks to gelo2002 for his flow. The NodeCode offered below is based on its free shared code. I just added a few (useful in my opinion) extensions. The main work has been done by gelo2002. 🙂
You can find information about his flow here:
Install the needed nodes
So that NodeRed can communicate with your Spotify-Account you have to install the node
Activate the Spotify Developer account
So that you can control the various functions of your Spotify account, you must first set up a developer account for your Spotify account. This is free of chage and is done with a few clicks. 🙂
To do this, go to the start page of your Spotify Developer Portal. You can use the following link:
After logging in with your account data, you must first accept or confirm the “Conditions”.
Then click on “Create App” …
… and enter a name and a suitable description for it. You can choose both as you like, but of course they should be reasonably meaningful. 🙂
Then you will be redirected to the overview of this “app” (this is what Spotify calls the developer access). There you will find the “ClientID” and the “ClientSecret” on the left. You will need both laterso you should write them down somewhere.
After you have clicked on “Edit Settings” in the overview, you will be directed to the view shown. There you have to enter the appropriate “Redirect Uri”. This Redirect Uri depends on the address of your NodeRed server.
If this can be reached, for example, at the address https:// server.fritz.box, the Redirect Uri would be as follows:
- https:// server.fritz.box:1880/spotify-credentials/auth/callback
Make sure that you select the correct protocol (i.e. http or https).
If you have entered the correct link, all you have to do is click on “Add” and (below) on “Save”.
Now to the actual NodeCode. This includes the control of the simplest functions. So you can pause and continue playback, select the next or previous track, “scroll” in the song and get the album cover displayed.
As always, you can find the NodeCode in the following part in the Nerdiy Git repository under:
Enter account access data in NodeRed
After you have created a developer access to your Spotify and inserted the NodeCode, you can now switch to your NodeRed configuration. Click on one of the Spotify nodes there and start configuring a new access there.
Now you have to enter your ClientID in the text field next to “ClientID” and your client secret in the text field next to “Client secret”.
You can find both in the previous step in your Spotify Developer access.
Next you have to enter the desired “Scopes”. Scopes stand for the services that you want to control from NodeRed.
For this flow here you can enter the following scopes:
streaming user-follow-modify user-read-currently-playing user-modify-playback-state
You can find a complete list at: https://developer.spotify.com/documentation/general/guides/authorization/scopes/
As soon as you have entered the scopes, all you have to do is click on “Start Authentication”.
This will open a new window in which you now have to confirm that you have allowed your NodeRed to access your Spotify account.
If you get an error message at this point, you can find a solution in the paragraph “Solution for error” INVALID_CLIENT: Invalid redirect URI “. 🙂
After you have confirmed this, you will be redirected to a website on which only the short message “spotify: authorized” is displayed.
Solution for error “INVALID_CLIENT: Invalid redirect URI”
The solution to the error reporting: INVALID_CLIENT: Invalid redirect URI I found here:
In principle, the error is caused by the fact that the “Redirect URI” was not configured correctly in the developer account. To get the correct Redirect URI, you can use the following trick.
Enter your URI in the URL decoder (https://www.urldecoder.org/) and let it decode.
The marked part in the lower field then corresponds to the Redirect URI, which you have to enter in your Spotify account.
The Spotify playback jumps or stalls sometimes
Every now and then it happens that the playback on one of my devices (no matter which one) jumps or stops. By trying it out, I found out that this seems to be related to the linking of the Spotify account with external services (for example the NodeCode presented here).
In retrospect, I explain it like this: Because Spotify wants to keep the playback data synchronized on all connected participants, I can imagine that a participant who answers too slowly could bring this synchronization out of sync.
Long story short: If you also observe this error: For me it helped to restart the computer on which NodeRed is running or, in the “worst case”, to unlink the Spotify account.
Have fun with the project
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂