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

    Lyricist III
    October 28, 2013
    It now also supports playMode in presets.

    Example:

    code:

    {
    "players": [
    { "roomName": "room1", "volume": 15},
    {"roomName": "room2", "volume": 25}
    ],
    "state": "stopped",
    "favorite": "my favorite name",
    "playMode": "SHUFFLE"
    }


    Valid values are: NORMAL, REPEAT_ALL, SHUFFLE_NOREPEAT, SHUFFLE

    The most confusing part of it is that "SHUFFLE" is with implicit repeat on. I might change the format to something like:

    code:

    "playMode": {"repeat": "on", "shuffle": "off"}


    Maybe that would be easier to comprehend.



    Great updates!
    I think that the second option would be better, especially if you will implement the Crossfade option as well.
    jishiAuthor
    Headliner II
    October 28, 2013
    Yeah, you are probably right. People probably think that crossfade should go in there as well.

    I have added a new feature, pauseall and resumeall. This will pause the currently playing zones, and remember for subsequent resumeall calls, which will resume the players that was playing when you paused them.

    Useful for home automation, when someone rings the doorbell or when you receive a phone call perhaps.
    jishiAuthor
    Headliner II
    October 29, 2013
    Just wanted to share that my previous on{x} script became a whole lot easier when having a raspberry pi in the background keeping track of the players.

    http://forums.sonos.com/showthread.php?t=30387&highlight=on%7Bx%7D

    new code:

    code:

    // Pauses the queue in the Sonos when a call starts
    device.telephony.on('busy', function () {
    device.ajax({
    url: 'http://192.168.1.112:5005/pauseall',
    type: 'GET'
    }, function () {});
    var notification = device.notifications.createNotification('Pausing players, click to resume');
    notification.on('click', function() {
    console.log('Resuming players from notification');
    device.ajax({
    url: 'http://192.168.1.112:5005/resumeall',
    type: 'GET'
    }, function () {});
    });
    notification.show();
    });

    // Pauses the queue in the Sonos when a call starts
    device.telephony.on('idle', function () {
    // resuming players now
    device.ajax({
    url: 'http://192.168.1.112:5005/resumeall',
    type: 'GET'
    }, function () {});
    });
    jishiAuthor
    Headliner II
    November 3, 2013
    From the idea shared here: http://forums.sonos.com/showthread.php?t=16130

    I added the simple feature to have an optional timeout with "pauseall", which can easily be used as a sleep function.
    jishiAuthor
    Headliner II
    November 6, 2013
    I have taken some time to revive the web controller project I was working on. I have now managed to get the top buttons working (prev, play, next) as well as the position bar (only status, no seek functionality), and the track info.

    This updates, instantly, if you control sonos from any other controller, like one would expect.

    http://upload.grabbarna.se/files/sonos-web-controller.png

    Might not be considered a huge leap in functionality, bit I spent most of the time rewriting stuff that wasn't well thought of. If I finish it, would you use it?
    buzz
    Grand Maestro
    November 7, 2013
    jishi,

    I have negative free time at the moment, but your projects, especially with the raspberry pi, are causing me to develop an "itch" to join the fun.
    jishiAuthor
    Headliner II
    November 7, 2013
    Hi buzz. Nice to hear that there actually is an interest, so my work isn't completely in vain :)

    I'll start a new thread for the web controller when I feel like the basic functions are fully functional, maybe that'll get more attention.
    Contributor I
    November 8, 2013
    Jishi,
    Fiddled around with the web controller using puppy linux and it is starting to look quite promising. Performance is excellent. Eventually I would like to host this server app on my Nas4Free box based on freebsd. I had the purple controller working a while back but its functionality is quite dated. My "clients" would be linux desktops, blackberry phones, android and apple "guest" devices and windows stations as well.

    Keep up the good work.
    jishiAuthor
    Headliner II
    November 8, 2013
    Jishi,
    Fiddled around with the web controller using puppy linux and it is starting to look quite promising. Performance is excellent. Eventually I would like to host this server app on my Nas4Free box based on freebsd. I had the purple controller working a while back but its functionality is quite dated. My "clients" would be linux desktops, blackberry phones, android and apple "guest" devices and windows stations as well.

    Keep up the good work.


    Nice to hear. supporting mobile devices will be the next step, and I will probably allow for a different layout for these devices (meaning, /m url would have a different template set). However, I think that Blackberry phones can be tricky to support.
    Contributor I
    November 8, 2013
    Nice to hear. supporting mobile devices will be the next step, and I will probably allow for a different layout for these devices (meaning, /m url would have a different template set). However, I think that Blackberry phones can be tricky to support.

    I will take a peek at how it looks / works on the BB Z10 and let you know.