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

    jishiAuthor
    Headliner II
    October 1, 2014
    I would be ok with having two different systems than could only be controlled independently but is that possible on the same LAN?

    Yes, that is no problem. Just setup the first players for the first system.

    When you setup the next system, and you are using the same controller, reset the controller first (I'm talking about the official Sonos controller now). This would create a new system, on the same LAN.

    The Sonos controller supports multiple households, but I'm not sure how this works if you are on the same LAN. Usually this is for supporting different systems on different networks (like, work and home). Maybe you will be able to choose if it finds two different systems, otherwise you would need to reset the controller and re-associate it when you want to switch. This is not a very common setup, that's why it might seem clunky.
    Lyricist III
    October 1, 2014
    Ok, i've set up two different systems on the same lan. But, as you said, the web controller attaches the the 'first response' and pulls only speakers attached to that system. Is there any way to tell the controller [your web controller] to attach to a specific ip as opposed to searching for first responding speaker/bridge?
    jishiAuthor
    Headliner II
    October 1, 2014
    Ok, i've set up two different systems on the same lan. But, as you said, the web controller attaches the the 'first response' and pulls only speakers attached to that system. Is there any way to tell the controller [your web controller] to attach to a specific ip as opposed to searching for first responding speaker/bridge?

    Not at the moment. I'm thinking of adding a setting for household ID, just give me a few days. You will be able to find your household ID here:

    http://[IP to one of the players]:1400/status/netsettings.txt

    The reason for using household ID is because I know it is part of the response when searching for players, and it's the same approach that the regular controller uses.
    jishiAuthor
    Headliner II
    October 5, 2014
    Ok, i've set up two different systems on the same lan. But, as you said, the web controller attaches the the 'first response' and pulls only speakers attached to that system. Is there any way to tell the controller [your web controller] to attach to a specific ip as opposed to searching for first responding speaker/bridge?

    I have pushed an update which supports a household filtering now. Create a file called settings.json and put the following in it:

    code:

    {
    "household": "HHID_XXxXxxxXXXXxxXXXXx"
    }


    Replace it with the household ID that you can find at http://X.X.X.X:1400/status/netsettings.txt

    from each system. Yours probably start with Sonos_ instead of HHID_, they changed it some time ago. Older systems will begin with HHID.
    Lyricist III
    October 6, 2014
    Jishi - your awesome. Works exactly like I asked. Now I can run 2+ sonos systems on the same lan using your web controller. This will be perfect for my situation as it will restrict people from only being able to listen to the music/stations/services i set whereas if i allowed them to use the SONOS controller they could do whatever they want. [the speakers will be out of reach for anyone to 'connect/sync' with their device/computer so they will be forced to use the great Jishi controller 🙂 Thanks again.
    Lyricist III
    October 6, 2014
    As if this controller isn't great already, should you ever get bored and find lots of time on your hands - the next feature regarding connectivity would be to only connect to speakers you set [i.e. in the settings.json file].

    This is similar to the previous request, but instead of having multiple sonos systems, have one system but only be able to see/control the speakers set in the settings.json file.

    I believe you touched on this in a previous post but just wanted to reiterate. The reason this scenario would be ideal would be so I could use the same music service accounts [i.e. Pandora] to control all speakers as opposed to having to purchase an account for each sonos system.

    But again, your household id update is fabulous and exactly what i asked for and fits my current needs perfectly. I appreciate your work on it.

    I hope to one day be able to understand how your created/scripted this controller so i can help contribute.
    jishiAuthor
    Headliner II
    October 6, 2014
    As if this controller isn't great already, should you ever get bored and find lots of time on your hands - the next feature regarding connectivity would be to only connect to speakers you set [i.e. in the settings.json file].

    This is similar to the previous request, but instead of having multiple sonos systems, have one system but only be able to see/control the speakers set in the settings.json file.

    I believe you touched on this in a previous post but just wanted to reiterate. The reason this scenario would be ideal would be so I could use the same music service accounts [i.e. Pandora] to control all speakers as opposed to having to purchase an account for each sonos system.

    But again, your household id update is fabulous and exactly what i asked for and fits my current needs perfectly. I appreciate your work on it.

    I hope to one day be able to understand how your created/scripted this controller so i can help contribute.


    Yeah, a blacklisting/whitelisting feature wouldn't be that hard to implement, and it could even be based on room name or UUID (IP-addresses could change). Then just void all the actions that are about the go out to the players (like volume, track change etc). The one issue that might not make sense is if all players are grouped, only one of the controllers would be able to control playback (play/pause/next/prev/seek) unless you would allow anyone to control it if grouped, but then one could just group it and control it, and then remove it from the group.

    However, this feature is really niche and would probably make more sense to be some sort of extension.
    jishiAuthor
    Headliner II
    October 16, 2014
    Hm, it seems to claim that it created the cache folder here:

    /opt/node-v0.11.2-linux-arm-pi/sonos/cache

    But you seem to be running the script from here:

    /opt/node/sonos

    Which one is correct? I haven't tested 0.11, maybe they've changed some stuff on how it discover different paths.

    I assume you haven't changed the cachedir with a settings.json file?

    Also, unless you have a specific reason for running 0.11, don't use it. It's unstable, and 0.11.2 is rather old. 0.11.x is not "newer" than 0.10.x, they use similar versioning as linux kernel.
    Lyricist I
    October 16, 2014
    never mind I was able to fix my error changing permissions. what I have run into is when running the regular web interface on a mobile device i cannot click on a button, it highlights but never actually clicks. looks like it requires a double click but on a tablet that causes a zoom not a selection if that makes sense.

    Ill run it with .10 and see if that changes
    jishiAuthor
    Headliner II
    October 17, 2014
    what I have run into is when running the regular web interface on a mobile device i cannot click on a button, it highlights but never actually clicks. looks like it requires a double click but on a tablet that causes a zoom not a selection if that makes sense.

    The regular GUI was never intended for touch devices. I have started working on an alternative view which is touch-enabled and responsive, but haven't had time to work on it lately.

    If you check out the mobile branch you can access it using /m and try it out.