Skip to main content
Headliner II
March 5, 2013

Sonos with node.js, my attempt!

INFO

Source code here: https://github.com/jishi/node-sonos-http-api
Sonos Web Controller draft (work in progress!): https://github.com/jishi/node-sonos-web-controller
Sonos IR control (requires lircd and IR reciever): https://github.com/jishi/node-sonos-remote-control

==============================================================


I know that there already is an attempt at this by this guy: http://forums.sonos.com/showthread.php?t=32643, but I found it to be a bit lacking in functionality so I decided to write up my own.

I have created a simple web-based API using what I have, which could be useful for integrating stuff with other applications. This web based API is inspired by other RESTful APIs, however I don't think it follows the correct guidelines to be called a REST API.

IT supports most basic features like:

play, pause, seek, next, prev, volume, mute, setAVTransportURI

It also supports these advanced fatures:

State of player as JSON, zone info as JSON, Play favorite item, presets (grouping, volume, avTransportURI)

You can read more in the README for each project.

To run it as a service under linux, I suggest using pm2 (https://github.com/Unitech/pm2). You need to run it in forked mode (-x)!

For Windows, you might try Winser http://jfromaniello.github.io/winser/

Cheers!
    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.

    391 replies

    Trending Lyricist I
    December 3, 2013
    Sorry no matter what i do nothing comes up in the dash info where in the code can o force a zone name or id ....I don't understand biggest zone I am sorry.....

    If I'm understanding the logic.... it's the device group with the most players....

    Lets say you have 10 devices total....

    Groups 5 players, 3 players, and a few singles....

    It would pick the 5 player group.
    Lyricist III
    December 3, 2013
    Yes it does work with groups only not a single player is there a way that i could force the player id in the script so it will work for a single player I am just learning here and so please excuse my lack of understanding I appreciate your patience ......Robert
    Contributor I
    December 3, 2013
    I have a single player in my setup (play5) and the dashboard is operating as expected in firefox. It would be nice to have the basic controls like volume, next, previous and play/pause along the bottom. Nothing fancy, just a nice layout for listening and viewing the album art
    Lyricist III
    December 3, 2013
    I do not dispute single player working it is when you have many players in your system the first player only will display if none are in a group I believe he did this to help me get a handle on the code am just trying to work out how to make it work a specific zone
    jishiAuthor
    Headliner II
    December 3, 2013
    As I said, it was never meant to be a controllable GUI, I only made it for my personal use in the Office.

    If you want to control which player you will use, you will need to modify the "topology-change" event, line 43 in index.html to make another selection based on some input parameter (#uuid or ?uuid), something like this:

    /dashboard/#RINCON_0058000000

    code:

    socket.on('topology-change', function (data) {

    var players = {};

    // make a hashtable of all players
    data.forEach(function (i) {
    players[i.uuid] = i;
    });

    // find which player you are interested in
    var desiredPlayer = players[location.hash.substring(1)];

    // now, we want the coordinator instead
    currentZone = players[desiredPlayer.coordinator];

    renderInfo();
    });


    It would probably be possible to rewrite it using roomName instead, but that requires some more thinking which I'm not capable of at the moment. If someone wants to create an enhanced version of this dashboard you are welcome to fork and send a pull request to me, but I will try and focus on some other alternative controller views.
    Lyricist III
    December 3, 2013
    No problem and many thanks........ for the guidance it really helps...
    jishiAuthor
    Headliner II
    December 12, 2013
    Been silent the last week, been trying to reclaim some sleep.

    However, got some news for you. The web controller now has a working master mute. I also re-made the content of all buttons in SVG which means that it will scale nicely when making the interface bigger. Also added some css effects for a better feeling.

    I also tried to make a fix when having multiple interfaces in your computer. Now it will search for Sonos players on all networks, and use then one which find a player first. Probably not of concern for most of you, but might help some of you with more advanced setups.

    Enjoy!
    Lyricist III
    December 13, 2013
    A gift for the holiday thank you ....:D
    jishiAuthor
    Headliner II
    December 14, 2013
    I'm sorry but I broke compatibility with node 0.8 in my last changes. This is fixed now. This is mostly for rasberry Pi-users, since it's a pain upgrading from source on it.

    EDIT: Actually, you can download pre-compiled version here:
    http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-arm-pi.tar.gz
    Lyricist III
    December 14, 2013
    A bit off topic but how does one run your code as a server on a raspberry as a service every time i redirect node server.js > robert.txt i do not return to the bash so i can run the other script .....thanks

    It does run though so the install is correct.....But have no clue what I am doing yet but learning....

    Thanks