Guide - controlling your Sonos AWAY from home through custom website

  • 22 January 2018
  • 0 replies
  • 3303 views

Userlevel 4
This is for the Google searchers out there. I don't expect this thread to be very relevant in the Sonos Community. I am going to create a guide to essentially allow you to port-forward your Sonos through your Router's firewall and control it whenever you are by visiting a domain/IP through your browser. :)

I'll make this as short as possible.

Firstly, download node.js (Google search, can't put links in posts) as that provides server-side Javascript that we can use to interact with Sonos away from home.

Secondly, download Jishi's HTTP API bridge for Sonos (Google search), and place it into a folder somewhere.

In that folder, create a .bat file with the line "npm install --production" and execute it to download the dependencies.
Once the dependencies are downloaded, edit the .bat file and replace the line with "npm start" to start the server.

When launching the server, make sure your Sonos system is visible to your PC. Check this by going into the Sonos app.

Now, to see if it worked go to "http://localhost:5005/state" and if it gives you a JSON interface with all your Sonos statistics you're golden.

To interact with your Sonos system, you have to amend the end of the URL (http://localhost:5005/[GROUP NAME]/[AMENDED ACTION])

For example, if I wanted to pause the player through the Sonos group "bedroom" I go to http://localhost:5005/bedroom/pause and the players assigned to the group pause. Of course, if you wanted to access this webpage outside your local network you replace localhost with your IP in which the port 5005 has been forwarded in your router.

All of the custom URLs can be accessed through Jishi's GitHub, and he/she also provides excellent documentation about how their API works!

To take things a little further, you can create a website (if you have the knowhow to do it) in which there is an organised UI to launch those URLs. In my website, I created a button that launches the associated URLs into a hidden iFrame to pause my players with the following button onclick code:

onclick="window.open('http://localhost:5005/Bedroom/pause','console')"

(You'll need to add the necessary button onclick HTML around it.)

By adding ,'console' to the end of the URL in the line it will load it into an iFrame instead which stops it from launching a new window entirely.

I cannot show you how to port forward your router, as every router is different.

But yeah, felt very bored so I wrote this. Enjoy. 🙂

This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.