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
We await the new version and thank you the ir part is off the hook and all 3 combined is the answer to complete the package any chance when you look at the code that you could allow us to send tts to the zones for a door bell or announcements etc ( when you have spare time) yea right :)

Thank You for all your hard work........

Regards

Robert
Userlevel 4
Badge +14
If anybody is interested, I did add support for replacing queue with one of your favorites.

example:

code:
http://localhost:5005/TV Room/favorite/MyAwesomePlaylist


Would replace the queue for the current group that TV Room is part of, with the favorite "MyAwesomePlaylist"

I will eventually add support for this in the presets as well, which means that you can resume a specific grouping, with pre-defined volume set and a predefined favorite list.

I will probably use this my self instead of the built in alarm, using the crontab daemon on the raspberry pi and do a 2-step wake-up call 🙂 slow music in the bedroom first 30 minutes, then all players in my apartment with some more up beat playlist.
Userlevel 2
Finally got a chance to try this - great work !. Just what I was looking for. Just set it up on a VM.

As a Squeezebox refugee, I was used to embedding the web control for music into other interfaces for geeky home automation projects. After switching to Sonos, I was forced to lose the integration and use separate official applications - always less elegant no matter how nice the dedicated app may be.

Took about 10 minutes to re-integrate into Command Fusion interfaces at home.

Keep up the good work.
And today I read about this thing: http://tessel.io/

I'm well aware that clock speed is only part of the story, but at 180MHz I wonder if it is fast enough for large JavaScript programs.
Userlevel 2
Good Morning :

Just checking to see if your or will you combine the mod into one so it is easier to install and run ...

Alo trying to install and run pm2 beside fork any other sug for rasp pi to make it run I seems to hitting a wall many thanks

Robert
Userlevel 4
Badge +14
I'm well aware that clock speed is only part of the story, but at 180MHz I wonder if it is fast enough for large JavaScript programs.


Yes, that part worries me too. The raspberry at 700 works pretty good but it can still choke when it has a lot to deal with.

However, it is running a full blown Debian setup, and could probably be stripped down quite a bit. Would be interesting to see how well it would behave.
Userlevel 2
HI Jishi,

How hard would it be possible to put a check so that if a favorite is already playing it won't attempt to reload the same favorite? I have found that certain Internet Radio stations take a long time to load in Sonos. If the command gets sent twice it can cause a long pause in what is playing.

Thanks
Userlevel 4
Badge +14
Now, as part of the 4.2 upgrade, the players now remember their queue and queue position it had prior to being grouped with other players.

This is a good thing, since that gives you the possibility to use different coordinators for different presets, and that way, you will be able to switch presets and keep the old queue, if each preset has a unique coordinator.
Userlevel 4
Badge +14
HI Jishi,

How hard would it be possible to put a check so that if a favorite is already playing it won't attempt to reload the same favorite? I have found that certain Internet Radio stations take a long time to load in Sonos. If the command gets sent twice it can cause a long pause in what is playing.

Thanks


For radiostations, not hard at all. For playlists it would be impossible to make a reliable identification of a certain favorite. It makes sense to not try and load the same radiostation twice.
Userlevel 2
Your software is exactly what I was looking for, great interface, responsive and easy to use.

Keep up the good work, can't way for music library browsing functionnality to be implemented.
Userlevel 2
Agree with guigui. Just got the web-controller up and running on my os-x machine.

And I've ordered a RaPi with IR to try to get your remote working.
Userlevel 2
Yes, you are running 0.6 of node.js, they changed it in 0.7 from "path" to "fs". I haven't run it under 0.6 in a long time, and I focused on 0.8 when I started. It might work, you can try and change this row (however, you might get other problems down the line):

code:
var fs = require('fs');


to

code:
var fs = require('path');


I assume you installed it using apt-get under debian/ubuntu, correct? If you don't want to compile and install it yourself, you can check this out: http://ypcs.fi/howto/2013/03/23/nodejs-debian/


Thanks! I updated to a newer nodejs, and now it works!

Looking forward to experimenting with this :)

Andreas
Userlevel 2
For those having issues getting lirc setup and configured the best how to I found was here:

http://www.jamesrobertson.eu/blog/2013/may/19/2326hrs.txt
Userlevel 2
I've got node-sonos-remote setup working great but it only manages one speaker at a time, even if they are grouped.

How could I manage the group volume?

Also, would it be possible to create a group. For example a preset that would always join Speaker A+B.
Userlevel 4
Badge +14
Thank you for your pointers, some bugs that was introduced in my last commits.

I have fixed them and pushed to github now. Enjoy!
Userlevel 4
Badge +14
I've got node-sonos-remote setup working great but it only manages one speaker at a time, even if they are grouped.

How could I manage the group volume?

Also, would it be possible to create a group. For example a preset that would always join Speaker A+B.


You can invoke
code:
player.coordinator.groupSetVolume("+2")


To control group volume instead. Personally I have mapped the channel up/down on my IR remote to control group volume, which means that to the "actions" object, I have added:

code:
"ch_up": function (player) {
player.groupSetVolume("+1");
return true;
}


Your IR codes probably differs from mine, but hopefully you get the idea. As you probably realize, +1, +2, +3 indicates increment steps (relates to % of volume)

Grouping can be achieved with presets, yes. There's an example preset (called "all") in sonos-lirc.js, you can just change that, and then map it to a key:

code:

var buttonToPreset = {
"KEY_1": "all"
};
Userlevel 2
jishi,

The group volume worked great and I thought the presets was working fine but now I see that it will only group on a fresh start of sonos-remote.

For example:
-Group the speakers via IR key
-Ungroup speakers via the Sonos app
-Attempt to regroup the speakers via IR key; it does not succeed (#1)
-Kill sonos-remote and restart sonos-remote
-Attemp to group via IR key and it does regroup. (#2)

#1:
00 KEY_POWER
before action true
applying preset { players:
[ { roomName: 'Living Room', volume: 51 },
{ roomName: 'Dining Room', volume: 51 } ] }
skipping breakout because already coordinator
after action false
Living Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Dining Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Living Room "urn:schemas-upnp-org:service:AVTransport:1#Play" STATUS: 200
emitting group-volume

#2
00 KEY_POWER
before action true
applying preset { players:
[ { roomName: 'Living Room', volume: 51 },
{ roomName: 'Dining Room', volume: 51 } ] }
skipping breakout because already coordinator
after action false
01 KEY_POWER
before action false
after action false
Living Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Dining Room "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI" STATUS: 200
Dining Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Living Room "urn:schemas-upnp-org:service:AVTransport:1#Play" STATUS: 200
emitting group-volume
emitting group-volume

You can see the contents of my sonos-lirc.js here:

http://ur1.ca/gvtr8

Also, out of curiosity:

-What is the difference between player.coordinator.groupSetVolume and player.groupSetVolume
-Are you using pm2 to run sonos-lirc as a forked daemon on your rapi?

P.S. I appreciate your support but if I'm consuming too much of your time feel free to tell me to bugger off.
Userlevel 4
Badge +14
player is the selected player, which in your case would always be TV Room since you don't have buttons to switch control.

player.coordinator is the coordinator player for a group. This is the player that you "initiated" the group from. According to your preset this would always be TV Room, but if you were to add "TV Room" to "Dining Room" from your Sonos controller, your groupVolume control wouldn't work.

I used pm2 ti run this yes, no problem. I have now switched my raspberry installation to rasplex, which is a bit dumber, so now I just start it with a autostart script like:
node sonos-lirc.js &
It won't restart if it crashes with this approach though.

It's weird that the preset only works one time, I haven't noticed this behavior in my setup. IT doesn't look like it breaks according to your logs either...
Userlevel 2
Muting is working, thanks!
A longer message is awaiting approval...
Userlevel 2
Bummer okay - I'll just restart the sonos-remote node every 5 minutes or so.
Userlevel 4
Badge +14
Seems like radio favorites needed to be handled differently than queue favorites. I added simple fix for it, but it might not work for custom radios (TuneIn should be fine though).

I also identified a few bugs in the preset system that I introduced in a rewrite, should work correctly now again.

"npm install" doesn't seem to update dependencies from git repos, so it's usually best to remove the node_modules folder and invoke "npm install" in order to get the latest version of sonos-discovery module.

Let me know if you have any more problems and I will try and sort it out.
Userlevel 4
Badge +14
Well, that's not really the optimal solution. I would need to get some info about the state of the players before and after you try and group them the second time.

If you could give me the info from http://IP:1400/status/perf

From both players and PM them to me. I only need the first few lines (10 or so), the rest is irrelevant.
Userlevel 4
Badge +14
For those who are interested, I pushed a new repository with a proof of concept for IR remote controlling your Sonos using a raspberry pi and a simple IR receiver.

https://github.com/jishi/node-sonos-remote-control

I use this myself with a left over IR remote, that controls the volume for my living room, and I've mapped the number keys to different presets and the media keys for play/pause/prev/next. Very neat.
Userlevel 2
As I was lacking the music library browsing feature which is my main use, so I decided to start developping it myself. I actually have something working.
It still needs some polishing and some functions (like adding a whole album to the queue for example) are still missing but browsing back and forth between artists and albums does work as well as going back to the previous menu.

jishi (or anyone else) : if you're interested I can send you the code in some way (via mail or github). Feel free to do whatever you want with it.

I do have one question though, one thing that I'm missing is the set of icons used by the Sonos app to have the same look & feel, I was wondering how you got the rest of the design ?

Best regards
Userlevel 4
Badge +14
Did you fork it on github? Then just send me a pullrequest and I'll try and merge it in.

I extracted most of the graphical elements from the Windows application, since they were basically embedded png resources. However, I wanted the gui to scale nicely, so I remade a lot of them in SVG and tried to reproduce most of it using standard css. Today it is only the volume scrubber and the shuffle/repeat/crossfade that are still images extracted from the Sonos application.

If you tell me which one you need I can easily extract them and add to the repo.