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

    NoBoB
    April 30, 2014
    However I just realized, I don't know what would happen for random playback, because I don't know when the random sequence is set, and if it get reset if you disable the queue temporarily. That might perhaps be a bit of a problem.

    I'd imagine using a Controller calls the same methods. If you load and shuffle a queue, start a radio station (queue goes into 'Not in Use' mode) then play the same track you previously interrupted, the 'Next' track is still the same one as before. The 'Next' track remains correct even if you resume further into the queue (meaning if you read ahead to know the play order, then skip back, interrupt the first track with radio, then resume at what would have been 4th in the shuffle, the 5th appears in 'Next').

    I was curious 🙂
    Matt W
    Sonos Employee
    April 30, 2014
    I've gotten voice feedback working: when the player is paused or stopped, double pressing the button puts you in favorites mode. The LED pulses, and your first favorite is spoken through the Sonos Zone. A twist of the knob says the next favorite, and so on. Pressing the knob once plays the last spoken favorite. Pressing twice (or doing nothing for 30 seconds) exits favorites mode back to a paused Sonos.

    The code is a disaster (when I code, I charge ahead full speed without care for comments or structure), so I'll spend the next few days cleaning it up, and working on the feel of the wheel turn/speaking timing, and get the new code posted.

    On a side note, I'd love for the PowerMate to have something like a magnetic haptic capability: setting the PowerMate to a certain mode introduces little "notches" in the turning motion. This would make selecting individual favorites far easier, and less of a cautious turn of the wheel.

    Jishi, I issued a pull request for a slight change that was helpful to me, but that will break other installs. Feel free to discard if you like. Just wanted to get it out there.
    Principal Sonos Developer Advocate
    Trending Lyricist I
    June 26, 2014
    Hi Jishi (and Matt!),

    Looks like Matts pull request #14 (add sub functionality) has introduced a problem in sonos-discovery...

    I have a stereo pair of play 1's and a bridge. When I fire up the web controller I see my devices listed in the console output, but I don't see any rooms listed in the UI so basically I can't control/play anything. If I separate the play 1's they both become visible as separate rooms in the UI and all works as expected.

    Everything works fine if I regress pull request #14 and #15 in sonos-discovery.

    I'll see if I can figure out what the problem is myself, but I must admit I'm struggling with node.js a little bit:)

    Thanks both for your work - looking forward to trying some ifttt recipes too;)

    Cheers,
    Dave.
    Matt W
    Sonos Employee
    June 26, 2014
    Really sorry about this. I tested basic pairing with just the sonos-discovery, but didn't try it "live" with anything like the web controller.

    Let me pair up a couple of my Sonos tonight, and get the web controller installed, and get this debugged.

    Sorry again. I hate that I broke something that was working so well for folks.
    Principal Sonos Developer Advocate
    Trending Lyricist I
    June 26, 2014
    Really sorry about this. I tested basic pairing with just the sonos-discovery, but didn't try it "live" with anything like the web controller.

    Let me pair up a couple of my Sonos tonight, and get the web controller installed, and get this debugged.

    Sorry again. I hate that I broke something that was working so well for folks.


    Many thanks Matt, I'll have another look this evening too. Out of interest, what IDE do you use? Nodeclipse?

    Cheers,
    Dave.
    Matt W
    Sonos Employee
    June 26, 2014
    Out of interest, what IDE do you use? Nodeclipse?

    I just use sublime text and the command line.
    Principal Sonos Developer Advocate
    Matt W
    Sonos Employee
    June 27, 2014
    I've submitted a pull request for to correct my (dumb) mistake. Hopefully it'll be accepted soon, and you'll be back in business.

    Sorry again.
    Principal Sonos Developer Advocate
    jishiAuthor
    Headliner II
    June 27, 2014
    Thanks for the quick fix, I have merged the pull request now.
    Trending Lyricist I
    June 27, 2014
    Excellent - many thanks Matt and Jishi:D
    jishiAuthor
    Headliner II
    July 1, 2014
    I have started working on the mobile version of the web controller, here is a quick screenshot:

    http://upload.grabbarna.se/files/Screen%20Shot%202014-07-03%20at%2023.55.09.png

    The good thing is that Chrome for Android now supports "Add to homepage" web apps, which means that you can hopefully get a native look and feel on it (Safari for iOS supports it as well).

    My first target is an improved volume control (with percentage feedback and easier to adjust at low volumes). I'll try and keep you posted.