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
    November 20, 2013
    one is using fix output setting correct
    jishiAuthor
    Headliner II
    November 20, 2013
    one is using fix output setting correct

    Hm, what version are you actually running? It looks like it's an old version. I have zipped up a new one and you can test with that.

    http://upload.grabbarna.se/files/node-sonos-http-api_0.4.3.zip
    jishiAuthor
    Headliner II
    November 20, 2013
    Found the volume control over the last release or two to be getting kinda funky. Response for volume control is slow and a bit less predictable. By that I mean, when I go to slide the volume up, it seems to go down a bit then up. The behaviour seems to be less predictable than a few releases ago. I will test further t o see if it's just me.

    I did a major rewrite of the volume element to support individual volumes, and I did notice similar behavior during development, but now I can't reproduce it? It's a bit problematic because when I adjust volume, I also get a notification that volume has changed, which i should act on IF another controller is the source of it. Problem being, I don't know that. What I do is that I don't act on the notification for a set time (800ms) after my own adjustment, to compensate for it. However, this isn't rock solid and might need tweaking.

    In which scenario do you experience it? mouse wheel, click or drag? And is it master volume or the player volumes that is worst?
    jishiAuthor
    Headliner II
    November 20, 2013
    I fixed the queue and favorites-update. It now reflects changes from other controllers, and it will switch queue when changing zones.

    Favorites will also be updated as soon as some other controller adds one.

    If you don't want to muck around with git, I did a pre-zipped version with all modules. Just unzip and run it with node.

    http://upload.grabbarna.se/files/node-sonos-web-controller-0.5.1.zip

    I also did a new screen cap to reflect the current state: https://www.youtube.com/watch?v=_7Dke5LsTF0

    Today I also installed this at work, which will be the main control interface for my co-workers. Will also use a screen-computer which runs chrome in kiosk mode, to present the currently playing track (today it just shows this interface, but I will make a "TV" interface for it which is only for information. Much like my Dashboard application I wrote in .NET, but which will run fine under a lightweight linux installation with X.
    Lyricist III
    November 20, 2013
    Good news its running (my fault forgot to change port) but will post error log as there are a few popping up

    Thank You....

    Robert
    jishiAuthor
    Headliner II
    November 21, 2013
    Well, of course it would break totally if you have an empty queue. Since 4.2 I rarely have empty queues any more, so I never noticed this. Anyway, I committed a fix for it. Thanks for the report.
    Contributor III
    November 21, 2013
    I can confirm that artwork issue has now been fixed :)

    I've written a blog entry about this project which may help some people not too familar with git/node.js.

    http://danonit.blogspot.com.au/2013/11/web-api-for-controlling-sonos-system.html

    I'm running the web controller on my NAS (Drobo-FS) and it's working a treat for basic control.
    Contributor I
    November 21, 2013
    Empty queue is pretty common if you move your sonos around the house. Thanks for the fix.

    I still do get the occasional null value error as well which crashes nodejs. Likely due to malformed or empty ID tags on mp3's. Have these issues been addressed yet? If to the best of your knowledge they have been addressed, I will look into more closely where exaclty I'm getting the null value.
    Thanks, yvon
    Lyricist III
    November 21, 2013
    Multiple nodes on one machine can you run both versions of your server on the same windows pc any I trying the web based and the html they seems to hang during init if one is running and thoughts? Is it better to run a Linux box and then run both servers? If so what flavor of Linux would be best?

    Many thanks and what a great project ........super job!
    jishiAuthor
    Headliner II
    November 21, 2013
    Empty queue is pretty common if you move your sonos around the house. Thanks for the fix.

    I still do get the occasional null value error as well which crashes nodejs. Likely due to malformed or empty ID tags on mp3's. Have these issues been addressed yet? If to the best of your knowledge they have been addressed, I will look into more closely where exaclty I'm getting the null value.
    Thanks, yvon


    Yeah, I didn't mean to sound rude, I was more being rude to myself for not testing it :)

    I thought the most of the null fails was adressed, but if you can give me error logs I will see what I can do.