Sonos with node.js, my attempt!



Show first post
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

Userlevel 2
Nice work, jshi! One question - do the Sonos APIs permit you to read current settings? For example, the current groupings and volume levels (including mute)? With this, a nice clean UI could be built to grab a snapshot of the current room settings to restore later.

If you could grab the current track name / artist / playlist and... dare I ask: album art?... then all kinds of nice UIs can be built for various devices.

Thank you in advance!
Philip
Userlevel 4
Badge +14
Nice work, jshi! One question - do the Sonos APIs permit you to read current settings? For example, the current groupings and volume levels (including mute)? With this, a nice clean UI could be built to grab a snapshot of the current room settings to restore later.

If you could grab the current track name / artist / playlist and... dare I ask: album art?... then all kinds of nice UIs can be built for various devices.

Thank you in advance!
Philip


Hi, it's a bit unclear what you are asking, especially considering it is in this thread. Are you wondering if the Sonos players can be read directly for the stuff you asked? Some of the things are possible, through different "hacky" unsupported ways, but the main concept is the opposite: The players will inform you when stuff changes, if you ask for it. The follow a subscription pattern, where you will register an endpoint that will be called when the player deems appropriate. This is standard UPnP Eventing.

However, what I created, and this thread is mostly about, is the HTTP API bridge that I created, which do expose the stuff that you are asking about. It will keep track of the state of the players, and expose simple HTTP commands that you can query at any time, and you will receive a response. It also supports a "preset" function, where you can apply a preset according to your own setup, which includes grouping, preferred play source and volume levels.

And regarding UI, I have used the same underlying software to build a web based controller, as well as a web based "dashboard" that shows the currently playing song, you can see the examples here:

https://www.youtube.com/watch?v=_7Dke5LsTF0
https://www.youtube.com/watch?v=0x-Nhzd0ueg

Was that what you had in mind? The last video was using a Samsung signage display with a built-in computer, but it would be fairly simple to replicate that using a raspberry pi2 with the same setup, you are able to install a fairly recent version of Chromium and run that windowless on that ARM-platform. It might not be as smooth (the samsung screen had an atom processor I think) though.
does sonos has any official control api? or any gadget to route the control to cloud service?
Userlevel 7
Badge +22
There is an official api.

You can get it by signing up here
http://musicpartners.sonos.com/
There is an official api.

You can get it by signing up here
http://musicpartners.sonos.com/


thanks Chris, but looks like this is music api for providing music service. What I meant is the sonos control api, like what Jishi did for "https://github.com/jishi/node-sonos-http-api". But for this server it requires either a laptop or hardware gadget to deploy. From sonos official, is there any similar solutions?
Userlevel 4
Badge +14
There is an official api.

You can get it by signing up here
http://musicpartners.sonos.com/


thanks Chris, but looks like this is music api for providing music service. What I meant is the sonos control api, like what Jishi did for "https://github.com/jishi/node-sonos-http-api". But for this server it requires either a laptop or hardware gadget to deploy. From sonos official, is there any similar solutions?


The only official way is to implement a UPnP based control point. Sonos follows that standard, with some proprietary additions, and is easily inspected with any UPnP scanner. However, it is overly complex for most minor tasks, and you need to keep track of states and handle events to get a fully functional API. My idea was to simplify that, primarily for crippled home automation systems that only handles simple HTTP calls.
Hello Jishi

Thanks for the amazing interface. I'm putting it to good use in my home automation setup.
I seem to be missing two things though:
- A call to get all sonos playlists (this already works for favorites)
- A way to play a specific url (e.g. a spotify url)
Am I looking in the wrong places? Anyway this would make the interface truly complete for me.

With regards
Userlevel 4
Badge +14
Hello Jishi

Thanks for the amazing interface. I'm putting it to good use in my home automation setup.
I seem to be missing two things though:
- A call to get all sonos playlists (this already works for favorites)
- A way to play a specific url (e.g. a spotify url)
Am I looking in the wrong places? Anyway this would make the interface truly complete for me.

With regards


Hi, and thank you!

Getting the playlists are not part of the system as of now. The playlist support was added by a contributor but it shouldn't be very hard to add the functionality to retrieve the playlists. Unfortunately there are a lot of other requests that hasn't been done yet so I can give you any timeframe when I will have the time.

Playing spotify url is partially supported in a test-version that I've made. See this ticket: https://github.com/jishi/node-sonos-http-api/issues/113 I had the idea of merging that but honestly I forgot about it. I can add that in the coming day or 2, to make everybody happy. Disclaimer, it is beta, and doesn't support multiple accounts. That however should be fine for some user cases.
Thanks for the fast reply. It would indeed be fantastic if you could merge that functionality.
I'll definitely try to add some functionality as well. Unfortunately I'm not that good with javascipt but I'm working on it 🙂.

Hello Jishi

Thanks for the amazing interface. I'm putting it to good use in my home automation setup.
I seem to be missing two things though:
- A call to get all sonos playlists (this already works for favorites)
- A way to play a specific url (e.g. a spotify url)
Am I looking in the wrong places? Anyway this would make the interface truly complete for me.

With regards


Hi, and thank you!

Getting the playlists are not part of the system as of now. The playlist support was added by a contributor but it shouldn't be very hard to add the functionality to retrieve the playlists. Unfortunately there are a lot of other requests that hasn't been done yet so I can give you any timeframe when I will have the time.

Playing spotify url is partially supported in a test-version that I've made. See this ticket: https://github.com/jishi/node-sonos-http-api/issues/113 I had the idea of merging that but honestly I forgot about it. I can add that in the coming day or 2, to make everybody happy. Disclaimer, it is beta, and doesn't support multiple accounts. That however should be fine for some user cases.
Userlevel 4
Badge +14
Thanks for the fast reply. It would indeed be fantastic if you could merge that functionality.
I'll definitely try to add some functionality as well. Unfortunately I'm not that good with javascipt but I'm working on it 🙂.


If you didn't notice, I merged this yesterday already, so feel free to play around with it!
Badge
Hi, i've just come across this effort for a web controller by you, it looks great and is exactly what i need for my home automation wall controller, but try as i can, i can't get anything to populate in the controller. I've installed it and can access it via the browser but it's just empty, no discovery etc. Am i doing something wrong?

Would really love to get the working.

Thanks
Userlevel 4
Badge +14
Sounds like it doesn't find your system. Could you please provide the output from the console, and also describe the environment where you are running this? Device, operating system, how it is connected to your network and if you can run an official controller on that device, does it work?
Badge
Hi, its a windows server, windows 2012 Just connected to the network via normal network connection, wired, with an IP address on the same network as the Sonos. If I run the official controller, it works fine. I've disabled all firewalls and so on. If you mean the output from the command prompt when i run it, that is below:

C:\Node>node server.js
no settings file found, will only use default settings
info - socket.io started
http server listening on port 8888
queue-changed { uuid: 'RINCON_000E5825AA6C01400' }
getqueue 0 600
loading-queue: 133.683ms
Userlevel 4
Badge +14
You could try disabling the firewall completely as a test. It might block the node process from opening a listening port.
Badge
I've tried that, no luck 😞
Badge
I've installed it on a different server own the network where I'm running many network services, as well as the original songs controller which works fine, and it's still not working, doing the same thing
Badge
ok here's the weird thing. If I reboot the Sonos so the queues are clear, then start the server.js, it shows this:


C:\Node>node server.js
no settings file found, will only us
info - socket.io started
http server listening on port 8888

As soon as I add songs to the queue with the official app, this get's added to the console

queue-changed { uuid: 'RINCON_000E5825AA6C01400' }
getqueue 0 600
loading-queue: 375.074ms

So it's definitely detecting something with regards to the player, but not showing this on the UI or allowing me to interact
Userlevel 4
Badge +14
Yeah, since it got a uuid, I would assume that the events actually works. Do you get any errors in your console in the browser?
Badge
do you mean the UI in the browser? then no, i just see the UI with nothing populated in it
Userlevel 4
Badge +14
do you mean the UI in the browser? then no, i just see the UI with nothing populated in it

Which browser? Most of them have a console that you can retrieve (F12 usually, in Windows), which might output some errors.
Badge
I've tried in IE, Safari on Mac, no difference, and the console from IE had an HTML error (which I fixed just to check) and that went away and there are no messages/errors logged in the console now
Badge
ok, interesting, i just installed it on my mac and it works. Must be something to do with Windows but i can't work out what it is!
Userlevel 4
Badge +14
I'll see if I can fire up a virtual win 2012 and see whats going on. Give me a day or two.
Badge
ok that will be great, thanks
Userlevel 4
Badge +14
I've tried in IE, Safari on Mac, no difference, and the console from IE had an HTML error (which I fixed just to check) and that went away and there are no messages/errors logged in the console now

I tested with a clean win2012 R2, and it runs without a glitch, I just needed to allow the node.exe program through the firewall. There must be something else going on. How is that machine connected to the network? Multiple interfaces? Any VPN or similar that might give issues?

Btw, both IE and Safari is unsupported. Safari probably works, IE, probably not. Target browsers are Chrome and Firefox, since they are cross platform.