Hi Chaps
I’m trying to use my Sonos system as a burglar warning. If someone breaks in (detected by OpenHAB) I want it to play a pre-recorded warning across all my speakers. However, it’s tricky and I’m taking baby steps.
What I have below is a sample of openhab.log, openhab.cfg, myfile.items, myfile.rules and myfile.sitemap for a very simple play/pause control of one of my Sonos players. It works on my install of OH 1.7.0. I hope it helps.
I’m still trying to work out how to pass a playlist or favorite name (eg “BurglarWarning”) to Sonos and get it to play it (especially under program control). No luck so far. I can’t get my head around how a string can be a command (see Sonos bindings list of commands “favorites”) or how to tell Sonos how to start playing a favorite. Any help welcome.
What I have learned is that the simple command referenced below works fine when my Dining Room player is not part of a group. It also works fine when it’s the “Zone Group” “Group Co-ordinator” on all players in the group. It won’t work if a different player is the Group Co-ordinator.
Since I use a Windows and two Android controllers for Sonos quite a lot, the “Group Co-ordinator” at any given time with my target player in the group can vary quite a bit. I need to find a workaround for this but suspect a simple but clunky way around it may be just to repeat the same command for every player I have, hoping one will work. Once I get a bit smarter, I may work out how to “ungroup” and “regroup” with my target player in control but that’s slow, even on a Windows controller.
For now, ungrouping all (on Windows, Android, IOS etc), then selecting your target (same as the one in OpenHAB) and adding other players to the group makes your chosen player the Group Co-ordinator. Sonos Alarms and any other automation or devices you use may then mess that up, so be warned.
openhab.log extract, using start.bat, so no verbose log files:
17:41:22.259 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S3) with UDN uuid:RINCON_000E5872025201400
17:41:22.264 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S3) with UDN uuid:RINCON_000E58F3071201400
17:41:22.439 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S1) with UDN uuid:RINCON_000E58CE71DC01400
17:41:22.759 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (ZP90) with UDN uuid:RINCON_000E58A21E4001400
17:41:23.059 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S3) with UDN uuid:RINCON_000E58F39D8801400
I used these RINCON values to configure my openhab.cfg file Sonos binding so I could refer to players by my room names:
sonos:Dining Room.udn=RINCON_000E58F39D8801400
sonos:Living Room.udn=RINCON_000E58A21E4001400
sonos:Kitchen.udn=RINCON_000E5872025201400
sonos:Master Bedroom.udn=RINCON_000E58F3071201400
sonos:Den.udn=RINCON_000E58CE71DC01400
Then, a restart of openHAB (assuming your bindings are OK) gives this in my openhab.log file (don’t look at dates, this is for explanation only, not chronological):
17:41:16.354 INFO o.o.c.s.AbstractActiveService[:169]- Sonos Refresh Service has been started
17:41:18.534 INFO o.o.b.s.internal.SonosBinding[:763]- Querying the network for a predefined Sonos device with UDN uuid:RINCON_000E58CE71DC01400
17:41:18.659 INFO o.o.b.s.internal.SonosBinding[:763]- Querying the network for a predefined Sonos device with UDN uuid:RINCON_000E58F39D8801400
17:41:18.749 INFO o.o.b.s.internal.SonosBinding[:763]- Querying the network for a predefined Sonos device with UDN uuid:RINCON_000E5872025201400
17:41:18.759 INFO o.o.b.s.internal.SonosBinding[:763]- Querying the network for a predefined Sonos device with UDN uuid:RINCON_000E58A21E4001400
17:41:18.774 INFO o.o.b.s.internal.SonosBinding[:763]- Querying the network for a predefined Sonos device with UDN uuid:RINCON_000E58F3071201400
17:41:18.784 INFO o.o.b.s.internal.SonosBinding[:768]- Querying the network for any other Sonos device
17:41:19.694 INFO o.o.i.habmin.HABminApplication[:182]- Started HABmin REST API at /services/habmin
17:41:22.259 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S3) with UDN uuid:RINCON_000E5872025201400
17:41:22.264 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S3) with UDN uuid:RINCON_000E58F3071201400
17:41:22.439 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S1) with UDN uuid:RINCON_000E58CE71DC01400
17:41:22.759 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (ZP90) with UDN uuid:RINCON_000E58A21E4001400
17:41:23.059 INFO o.o.b.s.internal.SonosBinding[:202]- Found a Sonos device (S3) with UDN uuid:RINCON_000E58F39D8801400
So far, so good.
My Sonos items file extract looks like this:
Switch SonosPlayPause “Sonos” {sonos="[ON:Dining Room:play],[OFF:Dining Room:pause]"}
Switch SonosPlayControl “Sonos Play/Pause”
and my sitemap file looks like this:
Switch item=SonosPlayPause
Switch item=SonosPlayControl
and my rules file looks like this:
rule "Sonos Play"
when
Item SonosPlayControl received command ON
then
sendCommand(SonosPlayPause, ON)
end
rule "Sonos Pause"
when
Item SonosPlayControl received command OFF
then
sendCommand(SonosPlayPause, OFF)
end
You may be thinking that I have one switch switching another switch on or off, which in turn turns my Sonos player on or pause. You’re right and from a user control point of view it’s unnecessary. Two switches appear and both will pause/play my player. However, I don’t intend to use openHAB as a user interface to Sonos. I prefer their own. However, I would like to put Sonos under openHAB control in extreme situations and want to learn how to control it programmatically. Such as to shout as loud as possible on all players “THERE’S A FIRE!” if my other sensors detect abnormal heat rise or freak any burglars out by talking in a sinister way to them as they go from room to room. So the SonosPlayControl and SonosPlayPause will be used experimentally in lots of ways before I remove them from my sitemap.
I’m not a programmer and I’ve found that using openHAB bindings, rules, items and so on to be a real pain. I’m an engineer by history and I’m used to quite exhaustive documentation. I love the idea and have invested heavily in time, effort and devices but I do feel held back by skimpy documentation on the github wiki and poor quality documentation that comes with most (say) Z-Wave devices. I, like you, find myself on forums like a forensic detective to try to piece together clues about how make bits work and do endless time consuming experiments, most of which fail.
I understand that this is open source and I’m delighted that it’s gathered so much momentum and support. I just wish I could find more detail for numpties like me.
If anyone wants to know how to control presence, lights (Hue and others), radiators and central heating, using Gcal calendar to control schedules for each room, let me know. I’ve more or less got that sorted.
Cheers
Vitchling