Sonos with node.js, my attempt!


Userlevel 4
Badge +14
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.

397 replies

Badge
Thanks for trying, to be honest, I'm not sure what's going on. everything else works fine on those servers, no multiple interfaces, no VPN, no VLANs, just directly connected to the same network as the sonos and the official controller works fine.

Not to worry though, I installed an Ubuntu VM on the windows server and installed it there, and that works fine, which is fine for me
I would love a way in the mobile screen to dictate the player is displays. I am trying to integrate something in a control application that will show as a URL.
Any way that can happen?

On second thought I could also just run multiple instances if we are able to dictate which players are picked up by the app.
Userlevel 4
Badge +14
I would love a way in the mobile screen to dictate the player is displays. I am trying to integrate something in a control application that will show as a URL.
Any way that can happen?

On second thought I could also just run multiple instances if we are able to dictate which players are picked up by the app.


I did a workaround for this for the dashboard view a while back, where you could append the UUID to the url (http://localhost:8080/#UUID_12345678901400) to force the selected group when loading the view, but I can't seem to find it right now.

I'm guessing you want this in order to have a fixed controller for a certain zone/player? Unfortunately the web-controller project hasn't gotten any love in the past year because of limited free time, but what you are asking for is fairly trivial to achieve.
That is exactly what I am looking for. Really just a status screen that shows currently playing art, title, and next up title for a specific player. I would be happy to donate to the cause if that could free up some of your time.
Userlevel 4
Badge +14
That is exactly what I am looking for. Really just a status screen that shows currently playing art, title, and next up title for a specific player. I would be happy to donate to the cause if that could free up some of your time.

I wish it did, but unfortunately not 🙂 the /dashboard view is actually what you are looking for then, see this video: https://www.youtube.com/watch?v=0x-Nhzd0ueg. However it doesn't have a flexible design atm and is designed for a full HD resolution, but it might be a good start if you are a bit familiar with HTML/CSS.
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.
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?
Userlevel 4
Badge +14
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.
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
Userlevel 1
Badge +3
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?
Userlevel 4
Badge +14
That is just a warning from an underlying dependency, nothing to worry about.
Badge
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
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?
Userlevel 4
Badge +14
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.
Userlevel 3
Badge +4
Nice work!
I know you were talking about adding "resume" at some point. What's the current status/limitations on this feature?
Userlevel 4
Badge +14
Nice work!
I know you were talking about adding "resume" at some point. What's the current status/limitations on this feature?


I'm not sure what you refer to when you say "resume". Care to clarify?