How to automate "play just this speaker" unless other speakers are playing in which case "join group"

  • 9 January 2019
  • 9 replies
  • 1513 views

Badge +1
I have 7 Sonos dotted around my house.

I enjoy the music filling the house so generally have "Play Everywhere" set, have all speakers in the same group and simple adjust the volumne as required (including muting rooms where I don't want music).

I want the Sonos in the toilet to turn on when I enter the bathroom and turn off when I leave afterwards.

If other speakers are playing then I would like the toilet speaker to simply "unmute" and then "mute" again, joining the music in the rest of the house.

If other speakers are not playing the I would like JUST the toilet speaker to "play" and then "pause" (I don't want other speakers to emmit sounds).

- The logic is simple however I need to know whether the other speakers are playing or not.
- And I need to have the ability, based on this info, to either "Play/Pause" the toilet speaker or "Unpause/Pause" JUST the Toilet speaker

Does Sonos API share this information And what tool would allow me to control it?

(Triggers would either be Hue Lights turning on, SmartThings Motion Sensor detecting movement ... or anything else!)

Thanks in advance,
Christopher

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.

9 replies

That's a pretty interesting scenario you've laid out. I'm usually not too concerned with automations, but that seems like a rather nifty feature for a guest bathroom. Here's the concerns I have.

- I think you would be able to use something like IFTTT to set part of the triiger/if condition to give true/false on whether or not audio is playing on specific speakers. I'm not aware that there is anything in the API to join an existing group. As far as I'm aware, you would only be able to create a new group and initiate new audio. However, you can check out https://developer.sonos.com/ to dig in deeper to see what is and isn't possible with the existing API.

- A motion detector would work to trigger entry into the room, but it would not be able to accurately trigger that someone has left the room. Turning the lights off seems like it would be much more effective for that, or perhaps assuming that 10 minutes is long enough. I guess not really a concern, more of a design comment.

edit: I'm going to correct myself. There is a Sonos API available to modify existing groups. I'm not aware of any existing service that allows you to do this with user-friendly setup steps (such as IFTT or Smartthings) though.

https://developer.sonos.com/reference/control-api/groups/modifygroupmembers/
Userlevel 7
Badge +23
I think you could probably achieve this with the current cloud api (amazingly). You would subscribe to metadata events for the toilet player, and use the group namespace to add and remove that from the everything group. Not sure how you would detect the actual use of the toilet, there's no API for that :-)

If you are not a programmer than IFTTT would be the way to go instead, I guess. I am not familiar with the details of that.
Badge +1
Its a 'real' scenario.

I want to have all the sound in the flat the same (its an averagely small city flat so I don't really have people in the flat wanting to listen to different music at the same time) ... so I have taken to using a single group all the time and just muting and unmuting to select or unselect rooms from the 'party'.

The basic command to 'Play' when the sensor sees motion is okay, but in it's most basic form would mean that someone walking into the bathroom would set music off throughout the flat. And likewise if the logic was set to 'Stop' when the person leaves the bathroom then leaving the bathroom would kill any music that was playing - not good for parties !

This is why I need to know what the status is of the rest of the Sonos.

If they are all playing then simply mute / unmute the bathroom
If they are not playing then mute all speakers and play and unmute the bathroom .... then simply 'Stop' on leaving the bathroom.

The bathroom is quite close to the rest of the flat / lounge so music in there would be nice for everyone !

Sonos have come back to me that IFTTT does not have details of the status of the speakers. However someone else has come back to me with that the SONOS CLOUD API does provide this information (https://developer.sonos.com/reference/control-api/playback/getplaybackstatus/)


So ... I am not too worried about the group stuff. I know how to mute and unmute based on sonos status to get what I want.
I could trigger the on and off via the motion sensor (there is a setting that say 'no motion detected for x mins') or I could use the Hue light turning on as a trigger.

I just need to wrap the information together (I don't know what to do with an API - eek!) and what tool to use to produce the logic. Any ideas ?

That's a pretty interesting scenario you've laid out. I'm usually not too concerned with automations, but that seems like a rather nifty feature for a guest bathroom. Here's the concerns I have.

- I think you would be able to use something like IFTTT to set part of the triiger/if condition to give true/false on whether or not audio is playing on specific speakers. I'm not aware that there is anything in the API to join an existing group. As far as I'm aware, you would only be able to create a new group and initiate new audio. However, you can check out https://developer.sonos.com/ to dig in deeper to see what is and isn't possible with the existing API.

- A motion detector would work to trigger entry into the room, but it would not be able to accurately trigger that someone has left the room. Turning the lights off seems like it would be much more effective for that, or perhaps assuming that 10 minutes is long enough. I guess not really a concern, more of a design comment.

edit: I'm going to correct myself. There is a Sonos API available to modify existing groups. I'm not aware of any existing service that allows you to do this with user-friendly setup steps (such as IFTT or Smartthings) though.

https://developer.sonos.com/reference/control-api/groups/modifygroupmembers/
Badge +1
If this requires professional development - what would I be asking someone to create. I am sure to a developer (Python?) this would be a short job !
Its a 'real' scenario.


Like I said, I like the idea. If a solution ends up being posted here, I might implement it my own home.


I want to have all the sound in the flat the same (its an averagely small city flat so I don't really have people in the flat wanting to listen to different music at the same time) ... so I have taken to using a single group all the time and just muting and unmuting to select or unselect rooms from the 'party'.

The basic command to 'Play' when the sensor sees motion is okay, but in it's most basic form would mean that someone walking into the bathroom would set music off throughout the flat. And likewise if the logic was set to 'Stop' when the person leaves the bathroom then leaving the bathroom would kill any music that was playing - not good for parties !


Regarding muting and unmuting, I don't know that this would be an ideal practice. If a particular speaker is part of a group that is playing audio, but it's volume has been muted, I don't think it will go into power saving mode. I get the convenience of the practice, but you are probably using more power then necessary, and putting extra wear on your speakers. It may be pretty negligible overall, but I wouldn't do this if there was anther way.



Sonos have come back to me that IFTTT does not have details of the status of the speakers. However someone else has come back to me with that the SONOS CLOUD API does provide this information (https://developer.sonos.com/reference/control-api/playback/getplaybackstatus/)


Yes, this sounds accurate to me. I haven't looked at IFTTT in a while, but I don't recall seeing any functionality around status. The Clould API does though, as you pointed out.


So ... I am not too worried about the group stuff. I know how to mute and unmute based on sonos status to get what I want.
I could trigger the on and off via the motion sensor (there is a setting that say 'no motion detected for x mins') or I could use the Hue light turning on as a trigger.


If your going to use the cloud API though, grouping and ungrouping would be a better option though since both options would be available. My opinion anyway.


I just need to wrap the information together (I don't know what to do with an API - eek!) and what tool to use to produce the logic. Any ideas ?


Nope. It looks the Cloud API isn't too hard to figure out if you have some basic programming experience. There harder part, to me anyway, would be to then tie in the commands to the API with the triggering event.
Badge +1
Thanks for your comment about muting / un-muting ... to be honest I am not that worried about the small differences between standby and muted speakers, but in the interests of cost and environmental savings I did a trial of running 3 speakers (2x Play3 and 1x ONE) off a single smart plug which measures usage and ran it in with 5 scenarios ....

Play Music 50% vol
Play Music 25% vol
Play Music 0% vol (mute) - music playing on other speakers in the flat
Music not playing Speaker not on mute
Music not playing Speaker not on mute

I played each scenario for an hour and measured the usage.

50% = 0.000 26 KwH
25% = 0.000 24 KwH
0%/Mute = 0.000 20 KwH
Pause =0.000 19 KwH
Pause/Mute = 0.000 19

In my rough test there was a slight difference between being muted and not playing ... however when I ran the test again the 0%/Mute fluctuated between 0.000 20 KwH and 0.000 19 KwH so I don't think that it is a significant factor.

Found this detail of power consumption when idle and it states (Idle is defined as audio muted or paused on all players in the household for at least 3 minutes) so I guess there is no difference. https://support.sonos.com/s/article/256?language=en_US

A great thought though - got me thinking about the solution 🙂
Badge +1
Now ... I wonder if you can help ?

I am a bit lost on how to use the API information, where to start and what to do ... given that you might also be interested in the solution are you able to give me a hand to find how to do it ?

https://en.community.sonos.com/smart-home-integrations-229108/can-smartthings-can-pause-play-sonos-but-does-it-know-the-current-state-6819066/index1.html#post16303017

I have found out this information about finding the 'current state' which would help with the question "Are the other speakers playing anything"

Are you any good at this stuff :)

Thanks,
Christopher
Now ... I wonder if you can help ?

I am a bit lost on how to use the API information, where to start and what to do ... given that you might also be interested in the solution are you able to give me a hand to find how to do it ?


I honestly don't think I can really help you out much here. I have an IT background and have some expertise in certain areas, but not really in this area. So I can read and comprehend the general idea and design of the API ok, but I really don't have any practical experience with this sort of thing. I'm sure I could research and figure out, but it would takes me weeks longer than it should to get it done...and I simply don't have the motivation to do it. ;-)

It is a useful project though that does make learning the general tech a bit more interesting. It is something I want to keep in mind if I ever do find the motivation to do so, or if knowledge of this sort of this could be beneficial in my career (highly unlikely).
Badge +1
Solved it .....

I have used WebCore to do all the logic (SmartThings Webcore) so that the trigger is the HUE light bulb in the bathroom ... when this is turned ON then the SmartThings Webcore programme checks whether any of the other Sonos Speakers are AND( Playing, Unmute, VolGreaterThan0%) ... if none of them are then I need to mute all and instruct a PLAY command. If any of them are then I simply need to instruct an UNMUTE command (as all are in the same group)

But ... Webcore cannot control a single speaker's volume,( it can mute unmute a single speaker but when changing the vol it changes the vol of the group, not the speaker) ... so I have used IFTTT to use the same trigger (Bathroom light) but use IFTTT to control the precise volume of the individual speaker when turned on (to 25%) and then when turned off to 0%.

One annoying thing is that this means when leaving the bathroom the mute is on and hence there is a green light ... but I can live with that.

If you would like more info ... please drop me a line ...

... I now have a bathroom that turns on music when nothing is playing in the apartment ... and if there is music playing then it joins the rest of the music .... when someone leaves the bathroom, the speaker turns off.

Perfect