Skip to main content

Sonos with node.js, my attempt!

  • March 5, 2013
  • 391 replies
  • 109618 views

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.

391 replies

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • December 10, 2014

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.

Forum|alt.badge.img+1
  • Avid Contributor I
  • December 11, 2014
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!

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • December 15, 2014
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!


Well, apart from the repeating issue, it still works the same way? I take it that the regrouping isn't an issue for you?

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • December 20, 2014


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.

Forum|alt.badge.img+1
  • Avid Contributor I
  • December 21, 2014
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!

  • Lyricist III
  • January 3, 2015
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?

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • January 3, 2015
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 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.

  • Lyricist III
  • January 4, 2015
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.

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • January 4, 2015

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.

  • Lyricist III
  • January 4, 2015
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?

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • January 4, 2015
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?


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)
}
});

  • Lyricist III
  • January 4, 2015
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});
.

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • January 4, 2015
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.

  • Lyricist III
  • January 4, 2015
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?

  • Lyricist III
  • January 4, 2015
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).

code:

// zero time has to be sent as empty string
if (timestamp == "00:00:00") {
timestamp = "";
}
console.log("sleep time",timestamp)

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • January 4, 2015
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.

  • Lyricist III
  • January 4, 2015
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.

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • January 10, 2015
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.

Forum|alt.badge.img
  • Contributor I
  • March 31, 2015
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?

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • March 31, 2015
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.

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.

Forum|alt.badge.img
  • Contributor I
  • March 31, 2015
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.

Forum|alt.badge.img+2
  • Lyricist III
  • April 19, 2015
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

Forum|alt.badge.img+14
  • Author
  • Headliner II
  • April 20, 2015
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


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?

Forum|alt.badge.img+2
  • Lyricist III
  • April 20, 2015
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

  • Lyricist I
  • May 16, 2015
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 🙂