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!
Page 14 / 16
code:
http://localhost:5005/{Room}/say/This is a test sentence. This Too. And this. /en
will produce the expected result, but the phrase from the first say command (Test) is repeated after the second phrase.
Does this only happen on my system?
I'm aware that issuing a "say" command to a player that has previously only issued a say command, would repeat the first say command once again. This is a bug, introduced when I tried to fix resuming. But it doesn't keep repeating it over and over again, that was what I was curious about.
The say command was contributed by another user and very experimental. The url syntax that is used isn't well equipped for this kind of stuff, and one would probably like more features for it to be useful, like:
grouping all players temporarily for a TTS message, then resume them again
Ungroup a player temporarily for a message and then regrouping it again (this works today)
Some sort of command builder with a text field where you can write anything in it and it would be escaped accordingly to allow for weird characters etc.
Ok, thanks for the feedback, jishi.
The previous version of the 'say' command, was very useful to me. I had written elaborate scripts announcing weather and stuff when movement in the bathroom was detected on weekday mornings. It still is useful to announce what radio station is about to be played (I use an rf remote, and one button scrolls through a list of favourite stations). Of course, the 'say' command is experimental and a work in progress. I'll stay with current version because of the other new features. Thanks!
The previous version of the 'say' command, was very useful to me. I had written elaborate scripts announcing weather and stuff when movement in the bathroom was detected on weekday mornings. It still is useful to announce what radio station is about to be played (I use an rf remote, and one button scrolls through a list of favourite stations). Of course, the 'say' command is experimental and a work in progress. I'll stay with current version because of the other new features. Thanks!
The previous version of the 'say' command, was very useful to me. I had written elaborate scripts announcing weather and stuff when movement in the bathroom was detected on weekday mornings. It still is useful to announce what radio station is about to be played (I use an rf remote, and one button scrolls through a list of favourite stations). Of course, the 'say' command is experimental and a work in progress. I'll stay with current version because of the other new features. Thanks!
Well, apart from the repeating issue, it still works the same way? I take it that the regrouping isn't an issue for you?
code:
http://localhost:5005/{Room}/say/This is a test sentence. This Too. And this. /en
will produce the expected result, but the phrase from the first say command (Test) is repeated after the second phrase.
Does this only happen on my system?
I have tried to fix the repeating issue. If you want to try it out, checkout the latest version.
Thanks you so much for your efforts, jishi! I've been quite busy, but I just saw your message, and installed the latest version. It works a lot better! Mostly everything is fine, almost like the previous version. I'll put my TTS functionality back up and see how it goes. Thanks!
Hi Jishi,
I have been using your excellent Sonos-lirc module running on a Raspberry Pi for a long time no without any problem, but now I would like to upgrade it a bit.
At my home everyone like to start playing every Sonos player but no one ever pause it then they leave the room :D
So I would like to have this option “automatically shut off if left playing but untouched for a selectable time” to save money (using 4G broadband) and bandwidth.
I think it would be rather “simple” to have an off timer (aprox 1-2 hours) who is retrigged every time the volume or sound source is changed.
Do you have any clue how to do this?
I have been using your excellent Sonos-lirc module running on a Raspberry Pi for a long time no without any problem, but now I would like to upgrade it a bit.
At my home everyone like to start playing every Sonos player but no one ever pause it then they leave the room :D
So I would like to have this option “automatically shut off if left playing but untouched for a selectable time” to save money (using 4G broadband) and bandwidth.
I think it would be rather “simple” to have an off timer (aprox 1-2 hours) who is retrigged every time the volume or sound source is changed.
Do you have any clue how to do this?
I have been using your excellent Sonos-lirc module running on a Raspberry Pi for a long time no without any problem, but now I would like to upgrade it a bit.
At my home everyone like to start playing every Sonos player but no one ever pause it then they leave the room :D
So I would like to have this option “automatically shut off if left playing but untouched for a selectable time” to save money (using 4G broadband) and bandwidth.
I think it would be rather “simple” to have an off timer (aprox 1-2 hours) who is retrigged every time the volume or sound source is changed.
Do you have any clue how to do this?
I gave it a thought, but I can't come up with a reliable solution for your problem. First problem would be that one would probably not touch volume or the playlist for several hours. I know I don't, but maybe you are using it in a different way.
Secondly, every re-subscription of the events, will trigger an event just as an update, which will act like someone had change source, volume or whatever kind of event you would use as a keep-alive check. You could of course increase the re-subscription period, but that will probably give you other issues. Next option would be to check for changes instead, but then I think the first problem would be evident.
With a broader perspective, you could consider expanding the idea to trigger from external sources instead. The most obvious solution would be motion sensors, but that is probably too big of a project, I'm assuming. Next one would be some sort of device polling, basically associating a room, with someones mobile phone. Given the criteria that if a phone drops from your home WiFi, you would pause certain players. You could also pause everything when all phones seems to be off WiFi (aka, no one home). This could be done from the phone, or from the rPI using some sort of polling mechanism. If you had multiple access points, you could perhaps also check which one the phone is associated with (but might not work very well in a small area like a house).
Using the phones capabilities, you could also utilize some geofencing techniques, however, in a home it would probably not be as granular as you would want it to be. This would be scriptable on android devices, using different tools, iphones would probably not be as easy.
Thanks a lot Jishi,
You really spend a great amount of your time to give me a lot of new thought on this issue.
The problem seems to be the re-subscriptions of events from other controllers (if I understand you correctly).
I was using Android (Tasker) but have switched to IPhone/pad to keep my headache on a reasonable level.
A different way could be to “always” set the timeout then the player goes from pause/standby to play, a bit like you already have implemented “function pauseAll(player, values)”, then you only have to toggle pause/play to keep listening.
Or how do I set the Sonos controller original function “Sleep timer (0:15)” from your http-api? By using this function I will be able to monitor it/change it from any Sonos controller.
You really spend a great amount of your time to give me a lot of new thought on this issue.
The problem seems to be the re-subscriptions of events from other controllers (if I understand you correctly).
I was using Android (Tasker) but have switched to IPhone/pad to keep my headache on a reasonable level.
A different way could be to “always” set the timeout then the player goes from pause/standby to play, a bit like you already have implemented “function pauseAll(player, values)”, then you only have to toggle pause/play to keep listening.
Or how do I set the Sonos controller original function “Sleep timer (0:15)” from your http-api? By using this function I will be able to monitor it/change it from any Sonos controller.
A different way could be to “always” set the timeout then the player goes from pause/standby to play, a bit like you already have implemented “function pauseAll(player, values)”, then you only have to toggle pause/play to keep listening.
Or how do I set the Sonos controller original function “Sleep timer (0:15)” from your http-api? By using this function I will be able to monitor it/change it from any Sonos controller.
That wasn't implemented, but seemed logical to add. It's added in 0.14 (requires discovery 0.14 as well), and you use it like this:
/RoomName/sleep/600 (10 minutes)
/RoomName/sleep/00:10:00
both formats are supported.
Jishi you are amazing,
The sleep function works perfectly and I also love the possibility to just set it in seconds.
I discovered that the volume was fading out on the last 4-5 seconds and this could be used to take action to resume playing if you still is listening.
Could you give me a hint were to find the code to hook into to detect volume/input change?
The sleep function works perfectly and I also love the possibility to just set it in seconds.
I discovered that the volume was fading out on the last 4-5 seconds and this could be used to take action to resume playing if you still is listening.
Could you give me a hint were to find the code to hook into to detect volume/input change?
The sleep function works perfectly and I also love the possibility to just set it in seconds.
I discovered that the volume was fading out on the last 4-5 seconds and this could be used to take action to resume playing if you still is listening.
Could you give me a hint were to find the code to hook into to detect volume/input change?
Sorry, forgot to expand on the event thing. I was probably vague, but the resubscription only applies to the node instance. When it resubscribes, it automatically triggers an event to the subscribing device. Not other controllers.
I've never noticed the fading volume before. Since the controller actually lowers the volume, it seems to be evented, which is good. In order to act on it, you will need to listen for the "volume" event from the discovery object. It will contain a state object, that would give you the current volume, so you would need to keep a reference to the old volume on each of these emits, to have something to compare with. Something like this:
code:
var volumes = {};
discovery.on('volume', function (e) {
if (!volumes[e.uuid]) {
// We don't have a volume entry, so trhis is the first event. Just store volume
volumes[e.uuid] = e.state.volume;
return;
}
// check if the volume is lower (potential sleep triggered)
if (e.state.volume < volumes[e.uuid]) {
// Volume was lowered, do something
// to get the player, use
// discovery.getPlayerByUUID(e.uuid)
}
});
Thanks,
I will give the code a try!
I just found that you can't put the sleep function in OFF mode once it started.
I have been looking at the discovery player.js but I can't figure out how to change in the SOAP string to be able to set sleep to OFF.
SOAP.ConfigureSleepTimer.format({time: time});
.
I will give the code a try!
I just found that you can't put the sleep function in OFF mode once it started.
I have been looking at the discovery player.js but I can't figure out how to change in the SOAP string to be able to set sleep to OFF.
SOAP.ConfigureSleepTimer.format({time: time});
.
Just send 0 as sleep time, that will disable it.
I noticed that it would reset the volumes if you set a sleep time, I assume the same is true of you send 0.
I noticed that it would reset the volumes if you set a sleep time, I assume the same is true of you send 0.
Just send 0 as sleep time, that will disable it.
I noticed that it would reset the volumes if you set a sleep time, I assume the same is true of you send 0.
I have try with zero time without any success, it still fade out and stop playing.
Like this “http://localhost:5005/Office/sleep/0”
I'm using two grouped Play1, but that shouldn't be the problem?
To set sleep to OFF the value should be an empty string "" and not "00:00:00"
so I have added the following code in module sleep.js function sleep(player, values).
so I have added the following code in module sleep.js function sleep(player, values).
code:
// zero time has to be sent as empty string
if (timestamp == "00:00:00") {
timestamp = "";
}
console.log("sleep time",timestamp)
Yeah, I thought it was equivalent. 0 triggered the sleep fadeout instantly, I just looked at the controller and saw the sleep countdown was removed.
I added an "off" value that does it instead. Seemed more intuitive.
I added an "off" value that does it instead. Seemed more intuitive.
I added an "off" value that does it instead. Seemed more intuitive.
Thanks sleep() works super now.
And your "volume change hook" code is also upp and running.
I just pushed an update to sonos-http-api with an attempt for a "announce everywhere" function, and then restore.
I know a few home automationers have been wanting this for a while, so try it out and see if it is useful.
I'll try and add a page later to control this or for "on the fly" announcements.
I know a few home automationers have been wanting this for a while, so try it out and see if it is useful.
I'll try and add a page later to control this or for "on the fly" announcements.
Jishi - did you ever solve for the repeating issue? Full disclosure - I am the author of a Sonos plugin for the Indigo home automation system. I have the same problem, but have been unable to figure out a solution.
Well, apart from the repeating issue, it still works the same way? I take it that the regrouping isn't an issue for you?
Hi, I think you need to refresh my memory and explain what the repeating issue was, or explain the symptoms that you are seeing, and I'll see if I can help. You are using SonosPy, correct? So it's more of a network/logic issue than directly related to my libraries? Maybe you should create a new topic where we can discuss this, to not add off-topic discussions to this thread.
Sorry - I just posted a new thread. This is not related to your code, but I found it interesting that you experienced a similar problem as me with text to speech announcements repeating a little of the text.
Hi, I think you need to refresh my memory and explain what the repeating issue was, or explain the symptoms that you are seeing, and I'll see if I can help. You are using SonosPy, correct? So it's more of a network/logic issue than directly related to my libraries? Maybe you should create a new topic where we can discuss this, to not add off-topic discussions to this thread.
First thank you for all you amazing work could you be so kind to direct me to how to force a player via the command line such as the following:
call to your web interface
http://192.168.1.160:8080/index.htm#RINCON_000E5813DC720140
this way i can force a specific player thus locking the interface from a user messing with another player.
Can see where to set the var: ( ps not areal programmer just learning) Thank you Robert
call to your web interface
http://192.168.1.160:8080/index.htm#RINCON_000E5813DC720140
this way i can force a specific player thus locking the interface from a user messing with another player.
Can see where to set the var: ( ps not areal programmer just learning) Thank you Robert
call to your web interface
http://192.168.1.160:8080/index.htm#RINCON_000E5813DC720140
this way i can force a specific player thus locking the interface from a user messing with another player.
Can see where to set the var: ( ps not areal programmer just learning) Thank you Robert
Are you trying to lock it down using some sort of widget load of the web interface (where a user can't manually change the URL)? Because otherwise it will be kind of pointless. You also need to consider how you want it to act if that player is grouped to another one. Allow access or not?
All I am trying to do is stop my kids from messing with the other players in the house and a guest when they come over just be able to control their room and not mess with the other the best way o thought was to just make a call to the web program remove the list of other players in the page ( hide them) and allow control for that player only as per groups etc I wanted to keep it simple if it was part of a group and the room was called it would be removed from the group and work on its own options to add to a group and other fancy stuff really not needed just need to select fav play stop etc many thanks for getting back Regards
Robert
Robert
Hi jishi,
thanks a lot for your awsume package!!
I was looking for a possibility to remote control my Sonos Play 5 and came across your package.
My Play 5 is connected to a TV in my bedroom. So, I was "only" looking for a possibility to increase, decrease the volumne while watching TV.
I managed to install all this on a raspberry and it is just working great. 🙂
I even somehow managed with my basic knowledge to integrate a "shutdown" command on a key press of my remote. As my raspberry is connected via USB Y-cable to my television, I thought that this might be better than just switch off the power. :-)
Thanks a lot again for your work on this package. Keep going 🙂
thanks a lot for your awsume package!!
I was looking for a possibility to remote control my Sonos Play 5 and came across your package.
My Play 5 is connected to a TV in my bedroom. So, I was "only" looking for a possibility to increase, decrease the volumne while watching TV.
I managed to install all this on a raspberry and it is just working great. 🙂
I even somehow managed with my basic knowledge to integrate a "shutdown" command on a key press of my remote. As my raspberry is connected via USB Y-cable to my television, I thought that this might be better than just switch off the power. :-)
Thanks a lot again for your work on this package. Keep going 🙂
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.