Bart Simons

Bart Simons


Thoughts, stories and ideas.

Bart Simons
Author

Share


Tags


.net .net core Apache C# CentOS LAMP NET Framework Pretty URLs Windows Server WireGuard WireGuard.io access log add analysis android api at the same time authentication authorization automate automation azure azurerm backup bash basics batch bootstrap build capture cheat sheet chromium chroot class cli click to close code snippet command line commands compile compiling compression containers control controller controlling convert cpu usage create credentials csv csvparser curl data dd deployment desktop detect devices disable diskpart dism distributed diy docker dom changes dotnet core drivers ease of access encryption example export file transfer files fix folders generalize getting started ghost ghost.org gui guide gunicorn gzip html html tables icewarp igd imagex import inotify install installation interactive ios iphone itunes java javascript jquery json kiosk kotlin linux live load data loading screen lock screen loopback audio lxc lxd lxml macos manage manually message messages minio mirrored mod_rewrite monitor monitoring mutationobserver mysql nexmo nginx no oobe node node.js nodejs not installing notification notifications object storage on desktop one command openssl owncloud parallels parallels tools parse perfect philips hue play port forwarding portainer.io powershell processing ps-spotify python quick raspberry pi record rip ripping rsync rtmp save save data sbapplication scraping script scripting scriptingbridge scripts security send server service sharedpreferences sms songs sonos spotify spotify api spotlight ssh stack streaming streamlink studio sudo swarm swift sync sysprep system audio systemd tables terminal tracking tutorial twilio ubiquiti ubuntu ubuntu 18.04 ui code unifi unlock unsplash source upnp uptime usb tethering wallpapers wasapi website websites webview windows windows 10 without itunes without oobe workaround xaml

Controlling Sonos devices with the Sonos API

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:

Sonos HTTP API

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 :)

Bart Simons
Author

Bart Simons

View Comments