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 4
Badge +14
Thanks... I tried the "," after both new presets, didn't realize that you need to not have it after the last one.....

OK, so now the server is starting....

Connecting through a browser and using:

:5005/presets/Thiev/Play

Output on yeah,I think screen:

code:

{ room: 'presets', action: 'AcidJazz', value: 'play' }
{ room: 'presets', action: 'Thiev', value: 'Play' }


But it's not doing anything to the players....

If I do the

code:

:5005/office/favorite/thievery corporation rdio radio


It was starting the stream.... with the current grouping. I was also able to stop it.

Thoughts?


yaEah, I think you are sending in /play at the end of the URL,which yuou shouldn't, it confuses it.

only invoke /preset/thiev and you should be golden.
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 4
Badge +14
Just to make sure, there can be no end slash either, or it will interpret the command incorrectly.
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?
Just to make sure, there can be no end slash either, or it will interpret the command incorrectly.

Check.... no trailing slash... unless chrome is "auto" adding....

Sample:

:5005/presets/test2
Userlevel 4
Badge +14
That is just a warning from an underlying dependency, nothing to worry about.
Userlevel 4
Badge +14
Check.... no trailing slash... unless chrome is "auto" adding....

Sample:

:5005/presets/test2


Well, it should be /preset/test2, it will parse it errorneous if you call it "presets", unfortunately.
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 2
Player playing display.....I saw you created a page to display what is playing etc could you or would you send it our way to play with many thanks

Robert

PS rasberry on its way oh boy more confusion on my life thanks again really enjoying your stuff and learning slow but learning
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 4
Badge +14
Player playing display.....I saw you created a page to display what is playing etc could you or would you send it our way to play with many thanks

Robert

PS rasberry on its way oh boy more confusion on my life thanks again really enjoying your stuff and learning slow but learning


Well, I can't really distribute it as is since it is both only Spotify centric (only works for spotify tracks because I download high-res covers from their web services), and because the font used is copyrighted. I will need some work to adjust this and have like a last.fm fallback for the cover arts or something.
Userlevel 2
No worry could you just create a simple example showing how to display in simple formatted

the return from the http call ip/zone/state I am trying but getting no where fast .... thank you Robert
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?
Userlevel 4
Badge +14
I can't reproduce that error. What is Office playing when you try and request the state? What does http://192.168.1.50:1400/status/perf say as current track?
Userlevel 2
Pandora some thing does not clear and trying to reboot sometimes clears it but i need to crash the server and restart ....some times it takes a few try to start the server as it crashes upon start up


AVT Play Log:

currently: PAUSED_PLAYBACK pndrradio:6500497454822409
951777329.841: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777329.782: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777329.673: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777329.547: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777329.462: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777329.414: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777329.290: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777328.498: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777328.448: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777328.356: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777327.909: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777323.619: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777323.619: state = PAUSED_PLAYBACK
951777311.436: track = pndrradio-http://audio-sjl-t1-2.pandora.com/access/2903629055255764799?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777284.070: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777283.380: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777212.870: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777211.907: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777206.406: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777181.910: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777181.780: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777138.142: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777138.095: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777137.946: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777137.877: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777137.755: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777126.659: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951777125.610: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951776991.706: track = pndrradio-http://audio-ch1-t2-1.pandora.com/access/3649818379862672283?version=4&lid=27816969&token=xT2%2FYnsGXGkdspL74
951776961.236: track = pndrradio-http://t1-1.p-cdn.com/access/?version=4&lid=27816969&token=Aff%2FCvCfN3JUclKArvkGYS1poXotTYU1sxeDjla74nwqbsvH
NodeRX Blocks:

Time avail full old dup oob nack
951777427: 0 0 0 0 0 0
951777303: 786 0 0 0 0 0
951777273: 724 0 0 0 0 0
951777243: 724 0 0 0 0 0
951777213: 724 0 0 0 0 0
951777182: 724 0 0 0 0 0
951777152: 724 0 0 0 0 0
951777122: 724 0 0 0 0 0
951777092: 723 0 0 0 0 0
951777062: 724 0 0 0 0 0
951777032: 724 0 0 0 0 0
951777002: 724 0 0 0 0 0
951776972: 1011 0 0 0 0 0
951776942: 724 0 0 0 0 0
951776912: 724 0 0 0 0 0
951776882: 724 0 0 0 0 0
951776852: 724 0 0 0 0 0
951776822: 723 0 0 0 0 0
951776792: 724 0 0 0 0 0
951776762: 724 0 0 0 0 0
CHSNK Fill Level:

Time =0 ^0 ^20 ^40 ^60 ^80 =100
951777427: 0 0 0 0 0 0 0
951777302: 4 424 452 456 456 2630 711
951777272: 0 0 0 0 0 3466 1130
951777242: 0 0 0 0 0 3459 1137
951777212: 0 0 0 0 0 3466 1130
951777181: 0 0 0 0 0 3462 1134
951777151: 0 0 0 0 0 3461 1131
951777121: 0 0 0 0 0 3465 1131
951777091: 0 0 0 0 0 3460 1136
951777061: 0 0 0 0 0 3467 1129
951777031: 0 0 0 0 0 3457 1139
951777001: 0 0 0 0 0 3462 1134
951776971: 1 428 448 456 452 3602 1032
951776941: 0 0 0 0 0 3462 1134
951776911: 0 0 0 0 0 3464 1132
951776881: 0 0 0 0 0 3455 1137
951776851: 0 0 0 0 0 3463 1133
951776821: 0 0 0 0 0 3460 1136
951776791: 0 0 0 0 0 3460 1136
951776761: 0 0 0 0 0 3462 1134
CHSRC Fill Level:

Time cnt t.ms avg.ftf max.ftf
951777427: 0 0 0 0
951777306: 1128 29328 15 61
951777276: 1148 29847 25 2412
951777246: 1150 29900 25 61
951777215: 1149 29874 25 60
951777185: 1150 29900 25 61
951777155: 1149 29874 25 65
951777125: 1148 29848 25 61
951777095: 1150 29900 25 61
951777065: 1149 29874 25 61
951777035: 1150 29900 25 61
951777005: 1149 29874 25 61
951776975: 1605 41730 18 80
951776945: 1149 29873 25 198
951776915: 1148 29848 25 61
951776885: 1150 29900 25 61
951776855: 1148 29848 25 61
951776825: 1149 29874 25 63
951776795: 1148 29848 25 61
951776765: 1150 29900 25 69
Userlevel 4
Badge +14
Which version of node.sj are you running? It seems like a really odd error. Also, make sure that you are running the latest version of both the http-api and sonos-discovery so the line-references will be correct.

I have added a simple dashboard example as well, for you to look at. just surf into http:/localhost:8080/dashboard/ or whatever IP you are using.
Userlevel 2
Will do as soon as i get home thanks maybe it is because i am running in windows but will update everything and try to recreate the error....
Userlevel 4
Badge +14
Will do as soon as i get home thanks maybe it is because i am running in windows but will update everything and try to recreate the error....

No, that can't be it, I'm running windows as well without any issues. The error seems to be caused by a JSON.parse call which receives a javascript object instead of a string, but I can't find any code related to it...
Userlevel 2
Ok will check i am running node v0.10.22 x64 ...

windows 7 .....I loaded the dash board and black screen how do i select zone to view ?

I have all the right updates will test later on ......
Hey J,

Updated both tonight.... will play around.

Also.... Just something to consider... I did a git pull for the http-api, and it complained about the fact that I have changed my presets.json.... So I just renamed the file, and put it back....

code:

remote: Counting objects: 3, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 2 (delta 1), reused 2 (delta 1)
Unpacking objects: 100% (2/2), done.
From https://github.com/jishi/node-sonos-http-api
1c2dbbc..8502f14 master -> origin/master
Updating 1c2dbbc..8502f14
error: Your local changes to the following files would be overwritten by merge:
presets.json
Please, commit your changes or stash them before you can merge.
Aborting


With yours as master.... do you think you should rename it in the branch so it doesn't conflict with a user version? Or should I just rename it first?

Coolness.... 47megs on the web, and 37 megs on the http, after running for 3 or 4 days.....
Userlevel 2
steelrat how did you get it working when i go to ip/dashboard i get blank just black
Userlevel 4
Badge +14
The dashboard just makes an estimate and selects the biggest zone. My real version uses the highres versions from Spotify so that one is nice and pretty. I added it more as a reference example, it isn't really meant to be a working dashboard and should be adjusted depending on screen resolution and music services used.

If you have updated to the latest commit, it should never complain about presets.json again. If it does, you might need to run:

git rm --cached presets.json

That would tell it to stop tracking that file.
Userlevel 2
Sorry no matter what i do nothing comes up in the dash info where in the code can o force a zone name or id ....I don't understand biggest zone I am sorry.....