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 II
    March 11, 2016
    With a little guidance I would imagine I can get this working.
    When loading http://localhost:8080/dashboard/#UUID_XXXXXXXXXXX where X is the UUID of one of my players the page loads blank.
    In fact just straight http://localhost:8080/dashboard loads blank.

    Really a way to specify player for the mobile version would be ideal.
    Lyricist I
    March 13, 2016
    I am trying to figure out of you can use this node.js to switch the sonos from the tv to pandora or from pandora back to the tv, do you know if that is possible?
    jishiAuthor
    Headliner II
    March 14, 2016
    I am trying to figure out of you can use this node.js to switch the sonos from the tv to pandora or from pandora back to the tv, do you know if that is possible?

    Probably, depending on the exact use case that you want. I'm using it personally to trigger line-in when my plex-client is starting playback, and could technically make it restore what was playing then plex-playback is stopped.

    However, there is no magical solution to a specific problem, but requires a bit of coding to make it fit your need.
    Lyricist I
    April 20, 2016
    Hi,

    This system is spot on what I need, the only thing is that I want to implement this into my whole home automation system that I'm building. Is there a chance to get this installed in the www folder on my Rasp Pi or should I link it somehow?

    I appreciate the work you have put in this system
    Avid Contributor I
    May 28, 2016
    Following jishis' instructions

    Start by fixing your dependencies. Invoke the following command:
    npm install --production

    Then I get lots of errors the last one being:

    npm ERR! Please try running this command again as root/Administrator.

    so i do
    sudo npm install --production

    Everything goes nicely except one error in capital red letters

    │ ├── UNMET PEER DEPENDENCY continuation-local-storage@~3

    I can run the server with nom start
    and jimmy's library works.
    But what does the error above mean?
    jishiAuthor
    Headliner II
    May 30, 2016
    That is just a warning from an underlying dependency, nothing to worry about.
    Trending Lyricist I
    November 3, 2016
    Thank you Jishi for all you have created for us! In hopes of publicizing my small new offering widely without being too spammy:

    "SonosAmpJuicePi"- solution for automatically powering on/off amps
    https://en.community.sonos.com/advanced-setups-229000/sonosampjuicepi-solution-for-automatically-powering-onoff-amps-6756435
    Lyricist I
    April 9, 2017
    Hi Jishi,
    your project is really excellent and opens up a load of possibilities, thanks a lot for having shared it!
    I have a question for you: I am trying to extend your http api with a new action to reproduce the audio part of videos from YouTube in Sonos. At the moment it's working fine, but the approach I am using is to convert the video to an mp3 stream, save it to a file in the Clips folder and then play that mp3 in Sonos using the Clip action. This means that I have to wait a few seconds for the mp3 file to be created before I can actually play it; it would be much better if I could reproduce directly the stream without passing through the creation of a file at all, but I have no idea of how to achieve it...
    Any thoughts?
    jishiAuthor
    Headliner II
    April 15, 2017
    Hi Jishi,
    your project is really excellent and opens up a load of possibilities, thanks a lot for having shared it!
    I have a question for you: I am trying to extend your http api with a new action to reproduce the audio part of videos from YouTube in Sonos. At the moment it's working fine, but the approach I am using is to convert the video to an mp3 stream, save it to a file in the Clips folder and then play that mp3 in Sonos using the Clip action. This means that I have to wait a few seconds for the mp3 file to be created before I can actually play it; it would be much better if I could reproduce directly the stream without passing through the creation of a file at all, but I have no idea of how to achieve it...
    Any thoughts?


    Hi. That is a bit tricky. What are you using for converting the video? You would need some software that does the conversion and outputting it as a http stream, then point your sonos towards that stream. I think vlc might handle that, but unsure. There is a newer thread about this software, or raise an issue at github for further discussion. Right now I'm on vacation, but I will be back in a week and can make some investigation.
    cariacou
    Enthusiast I
    January 18, 2019
    Nice work!
    I know you were talking about adding "resume" at some point. What's the current status/limitations on this feature?
    Feature request: Guest Mode. Ex: Add an admin login to the Sonos app to restrict desired settings/zones to non-guest users