Skip to main content
Headliner II
Mar 5, 2013 10:27 PM UTC

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
    Feb 4, 2014 12:46 PM UTC
    We await the new version and thank you the ir part is off the hook and all 3 combined is the answer to complete the package any chance when you look at the code that you could allow us to send tts to the zones for a door bell or announcements etc ( when you have spare time) yea right :)

    Thank You for all your hard work........

    Regards

    Robert
    Translate
    Contributor I
    Feb 5, 2014 2:47 PM UTC
    Finally got a chance to try this - great work !. Just what I was looking for. Just set it up on a VM.

    As a Squeezebox refugee, I was used to embedding the web control for music into other interfaces for geeky home automation projects. After switching to Sonos, I was forced to lose the integration and use separate official applications - always less elegant no matter how nice the dedicated app may be.

    Took about 10 minutes to re-integrate into Command Fusion interfaces at home.

    Keep up the good work.
    Translate
    Lyricist III
    Feb 22, 2014 2:09 PM UTC
    Good Morning :

    Just checking to see if your or will you combine the mod into one so it is easier to install and run ...

    Alo trying to install and run pm2 beside fork any other sug for rasp pi to make it run I seems to hitting a wall many thanks

    Robert
    Translate
    Lyricist II
    Feb 24, 2014 4:55 PM UTC
    HI Jishi,

    How hard would it be possible to put a check so that if a favorite is already playing it won't attempt to reload the same favorite? I have found that certain Internet Radio stations take a long time to load in Sonos. If the command gets sent twice it can cause a long pause in what is playing.

    Thanks
    Translate
    jishiAuthor
    Headliner II
    Feb 24, 2014 5:20 PM UTC
    HI Jishi,

    How hard would it be possible to put a check so that if a favorite is already playing it won't attempt to reload the same favorite? I have found that certain Internet Radio stations take a long time to load in Sonos. If the command gets sent twice it can cause a long pause in what is playing.

    Thanks


    For radiostations, not hard at all. For playlists it would be impossible to make a reliable identification of a certain favorite. It makes sense to not try and load the same radiostation twice.
    Translate
    Lyricist II
    Mar 13, 2014 1:43 PM UTC
    Your software is exactly what I was looking for, great interface, responsive and easy to use.

    Keep up the good work, can't way for music library browsing functionnality to be implemented.
    Translate
    Lyricist III
    Mar 14, 2014 7:44 PM UTC
    Agree with guigui. Just got the web-controller up and running on my os-x machine.

    And I've ordered a RaPi with IR to try to get your remote working.
    Translate
    Lyricist III
    Mar 18, 2014 11:59 PM UTC
    For those having issues getting lirc setup and configured the best how to I found was here:

    http://www.jamesrobertson.eu/blog/2013/may/19/2326hrs.txt
    Translate
    Lyricist III
    Mar 19, 2014 1:18 AM UTC
    I've got node-sonos-remote setup working great but it only manages one speaker at a time, even if they are grouped.

    How could I manage the group volume?

    Also, would it be possible to create a group. For example a preset that would always join Speaker A+B.
    Translate
    jishiAuthor
    Headliner II
    Mar 19, 2014 10:19 AM UTC
    I've got node-sonos-remote setup working great but it only manages one speaker at a time, even if they are grouped.

    How could I manage the group volume?

    Also, would it be possible to create a group. For example a preset that would always join Speaker A+B.


    You can invoke
    code:
    player.coordinator.groupSetVolume("+2")


    To control group volume instead. Personally I have mapped the channel up/down on my IR remote to control group volume, which means that to the "actions" object, I have added:

    code:
    "ch_up": function (player) {
    player.groupSetVolume("+1");
    return true;
    }


    Your IR codes probably differs from mine, but hopefully you get the idea. As you probably realize, +1, +2, +3 indicates increment steps (relates to % of volume)

    Grouping can be achieved with presets, yes. There's an example preset (called "all") in sonos-lirc.js, you can just change that, and then map it to a key:

    code:

    var buttonToPreset = {
    "KEY_1": "all"
    };
    Translate