Sonos speakers are awesome. I have owned a Sonos Play:3 for almost one month now and I must say that I am surprised by the design, sound quality and support. And did you even know you can control your Spotify devices programmatically?
This post is going to be a quick overview on how this works, and believe me: it is pretty simple to be honest!
What do I need to get started?
First of all, you need Node.js to be installed on your computer. This is the programming language that our dependency uses, which brings us to the next thing that is needed: the software that makes Spotify devices easily accessible through a REST API.
This is everything you need to get things working. Just two things. Can't get easier, right?
Check, check, double check.
Do I have Node.js installed on my computer? If you are unsure about that, just go ahead and install it. Go to nodejs.org and download the installer. If you get prompted to install npm, choose to install that too as it's a requirement for this to work.
Once Node.js is set up, you'll need to download the node-sonos-http-api package from GitHub. You can download the latest version from here as a zip file.
Now that you have everything ready to go, open up a terminal or a command prompt window and change your working directory to the node-sonos-http-api-master folder. Run the following command:
npm install --production
And
npm start
If you get a message in your terminal or command prompt that looks like
http server listening on 0.0.0.0 port 5005
Then you are good to go! Open up your web browser and go to
http://localhost:5005
You should be presented with a screen like:
This is a small documentation page to show the possibilities and features to you. Going to http://localhost:5005/zones
for example returns a list of zones available in your Spotify network in JSON format. Search for the value linked to the roomName property in your result to obtain your Spotify room name. I have a zone called StudyRoom and I am going to use this zone for further demonstration purposes in this post.
Pausing and resuming my music
This can be achieved by navigating to:
http://localhost:5005/StudyRoom/pause
I can also resume my music by navigating to:
http://localhost:5005/StudyRoom/play
Skip a track or go back
Need to skip a track? No problem.
http://localhost:5005/StudyRoom/next
Gets the job done.
http://localhost:5005/StudyRoom/previous
In case you ever need to go to the previous track.
Need to play louder? Or are you neighbors complaining?
http://localhost:5005/StudyRoom/volume/+10
This turns the volume up by 10%.
http://localhost:5005/StudyRoom/volume/-5
Use this to turn down the volume by 5%.
http://localhost:5005/StudyRoom/volume/3
To play at whisper quiet volume (3%).
Need to get the status of your Sonos room?
http://localhost:5005/StudyRoom/state
Returns the state of the room to you.
I hope that this article was useful to you. If it did, please show some support to jishi on GitHub by starring the node-sonos-http-api project. That's all for now, folks. Have a great evening :)