Skip to main content
Headliner II
Jun 20, 2016 11:24 AM UTC

Simplified HTTP API (node.js)

Hi, I'm starting a new thread regarding this (old one here https://en.community.sonos.com/advanced-setups-229000/sonos-with-nodejs-my-attempt-33834) since that one grew out of hand.

I have made some major improvements to the simple HTTP API that I've built, and it now also comes with a pre-composed raspberry pi image that runs from a RAM-drive (based on AlpineLinux) for even simpler installation.

This software is useful for simple integration with home automation in mind, or for small hobby projects.

For more information, see http://jishi.github.io/node-sonos-http-api/

File issues at github https://github.com/jishi/node-sonos-http-api/issues

Have fun!
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.

36 replies

jishiAuthor
Headliner II
Dec 8, 2016 2:21 PM UTC
Thanks so much for providing this API! It is really cool! I'm working on creating a node.js app with a scheduler to turn on my music automatically. I've noticed that occasionally when I give pause and resume commands to my sonos using my computer it will not do anything. If I try to hit the URL and do /zones or anything it will just return a blank array [] . Then, if I hit the play button on the actual sonos it will start working again and will receive commands. Is this a known issue or do you think something could be wrong with my sonos? My whole idea is based around my node server being able to wake up the sonos and start playing a specific playlist, so I would hope it would be possible.

That sounds really odd. If the zones return an empty array, that means the system hasn't been discovered. Are you sure the application isn't constantly restarting for some reason? Try to get the output from stdout when running it, and file an issue at github for it, and I'll take a look.
Translate
Lyricist II
Dec 8, 2016 2:42 PM UTC
Thanks so much for providing this API! It is really cool! I'm working on creating a node.js app with a scheduler to turn on my music automatically. I've noticed that occasionally when I give pause and resume commands to my sonos using my computer it will not do anything. If I try to hit the URL and do /zones or anything it will just return a blank array [] . Then, if I hit the play button on the actual sonos it will start working again and will receive commands. Is this a known issue or do you think something could be wrong with my sonos? My whole idea is based around my node server being able to wake up the sonos and start playing a specific playlist, so I would hope it would be possible.

That sounds really odd. If the zones return an empty array, that means the system hasn't been discovered. Are you sure the application isn't constantly restarting for some reason? Try to get the output from stdout when running it, and file an issue at github for it, and I'll take a look.


I looked a little further and it looks like it does return zones. But, if I try pauseall or resumeall using the URL in chrome it doesn't do anything and returns the [] that I mentioned. The app output shows 'resuming all players' each time I make the http request, but nothing happens. If I go over and hit the pause button on the sonos it will resume playing just fine. By output from stdout do you mean a logging file or simply the command line output that is generated?
Translate
jishiAuthor
Headliner II
Dec 8, 2016 2:52 PM UTC
With stdout I mean the command line output from the server console. For the raspberry image, this is redirected to a log file, but if you are running it manually, it would print out directly to the console.
Translate
Lyricist II
Dec 29, 2016 5:31 PM UTC
Hi,
really great job - I got your api working on my RaspberryPi.

But there are a few things open which I couldn't find out. Maybe I'm blind :-)

I get an event every time the current track changes. That works fine. I can save the json element of the state. Now I like to play a track again. But how can I start a specific track? My tracks are from my music library, from spotify and from apple music. Those tracks aren't saved in any playlist or favorite list.

What I'm doing wrong? Can someone post an example for me?

Regards
Translate
MarcusMaker
Lyricist II
Jan 2, 2017 6:11 PM UTC
Some really great work you've done here!
Yesterday I installed it on a Raspberry PI running Windows IoT Core and it worked without any changes at all!
Translate
marcusmaker
jishiAuthor
Headliner II
Jan 2, 2017 10:12 PM UTC
Hi,
really great job - I got your api working on my RaspberryPi.

But there are a few things open which I couldn't find out. Maybe I'm blind :-)

I get an event every time the current track changes. That works fine. I can save the json element of the state. Now I like to play a track again. But how can I start a specific track? My tracks are from my music library, from spotify and from apple music. Those tracks aren't saved in any playlist or favorite list.

What I'm doing wrong? Can someone post an example for me?

Regards


I'm not really following your question. You need to provide more details for me to be able to help you. "Event every time", are you using the webhook?

Tracks are usually part of the queue, So you usually just do a trackSeek to the correct trackNo if you want to jump back and forth between sources, but I'm guessing that is not what you are asking. Again, if you could be more specific and paint the scenario, I might be able to give you an answer.
Translate
jishiAuthor
Headliner II
Jan 2, 2017 10:16 PM UTC
Some really great work you've done here!
Yesterday I installed it on a Raspberry PI running Windows IoT Core and it worked without any changes at all!


Are you saying that this works without any issues with the Chakra engine version of node.js? That's good to know!
Translate
MarcusMaker
Lyricist II
Jan 3, 2017 9:18 AM UTC
Some really great work you've done here!
Yesterday I installed it on a Raspberry PI running Windows IoT Core and it worked without any changes at all!


Are you saying that this works without any issues with the Chakra engine version of node.js? That's good to know!


Yepp 🙂 I installed the Node.js addition to Visual Studio from here: https://github.com/ms-iot/ntvsiot. Then I created a new project of the type "Basic Node.js Web Server (UWP)", copied all the files from your project and deployed to the PI with Windows IoT Core.



It just worked!
Translate
marcusmaker
MarcusMaker
Lyricist II
Jan 13, 2017 9:10 AM UTC
Hi jishi!
Is there a way to know when the dicoveryprocess i done? Maybe a webhook?
Translate
marcusmaker
jishiAuthor
Headliner II
Jan 13, 2017 2:10 PM UTC
Hi jishi!
Is there a way to know when the dicoveryprocess i done? Maybe a webhook?


You will receive a topology-change webhook as soon as it has discovered your system, if you have defined a webhook. So yes, there is.
Translate