Sonos help

Hello, im a total newbie when it comes to openhab, im trying as a first task to get my sonos system working, i have read as much as i can and experimented but havent been successfull, is there someone out there that mabe can post there
openhab.cfg,items and sitemaps that corresponds with the sonos bindings so i have an example to work off.

Best regards / Chris

[quote=“ChrisE, post:1, topic:4945, full:true”]
i have read as much as i can and experimented but havent been successfull.[/quote]

I suggest starting with the binding wiki, there are examples you are looking for.

i have read it, but i cant get it to work i have tried many diffrent things, the examples i find dosent show how it should look throw all the files, thats why im asking if someone can post there openhab.cfg item and sitemaps that corresponds with the sonos coding.

i do not have any experience when it comes to koding but i whant to try to get this to work and lern some of the basics but i need a bit of help, most of what i have read requires the reader to have more skill then i have apperently :smile:

i have runned the demo and i get the general idea how it works, i have loded the sonos addon and tried severl diffrent lines of code but i cant get it to work, so plz maybe someone can help me instead of just assuming i havent treid anything and havent read anything !!

If you meant me: I didn’t assume anything. You asked for examples and I showed you where to find it.
I’m sure users who are using this binding will help you.
If you don’t get any further answers post your items and configs so we are able to figure out what you maybe did wrong.
Good luck.

Hi,
the main question is, what you would like to achieve (see on your sitemap).

Let’s start simple, switching a Sonos ON/OFF and changing the volume

Item
Switch Sonos “Power Sonos” { sonos="[ON:RINCON_XXXXXXXXXXXXXXXXX:play], [OFF:RINCON_XXXXXXXXXXXXXXXXX:stop]" }
Dimmer VolumeSonos “Sonos Volume” { sonos="[RINCON_XXXXXXXXXXXXXXXXX:volume]" }

Sitemap
Switch item=Sonos
Slider item=VolumeSonos

There are some more examples on the WIKI page for the binding.

Best
Hans-Jörg

Thank u i got play and pause and next and so to work thanks to u :slight_smile: i cant get volume to work, the debug says

19:33:33.165 [INFO ] [runtime.busevents :22 ] - Sonosvolume receiv
ed command DECREASE
19:33:33.165 [ERROR] [.b.sonos.internal.SonosBinding:313 ] - An exception occur
ed while verifying command compatibility (null)
19:33:33.180 [ERROR] [.b.sonos.internal.SonosBinding:327 ] - DECREASE is an unr
ecognised command for Item Sonosvolume

Regards/Chris

Whar UI are you using on which browser ???
Are you seeing a slider or an up and down arrow?

There are known limitations with the classic ui and internet explorer, not rendering a slider but up and down butons instead.
Please try the slider with native Android or IOS app or google chrome.

Best
Hans-Jörg

I have been fighting this for days, trying to control my Sonos. I am running openHAB 1.8

I can successfully control Insteon devices, so it looks like my system is working OK.

I configured my Sonos in the .cfg file. That seemed to work OK as the logs showed that the Sonos was found with the address I configured. I can see the commands going out, but nothing is happening. I tried the binding and sitemap config shown in this post, but it does not seem to work either.

/* Sonus binding RINCON_00011318566501400 */
Switch Sonos “Power Sonos” { sonos="[ON:RINCON_00011318566501400:play], [OFF:RINCON_00011318566501400:stop]" }
Dimmer VolumeSonos “Sonos Volume” { sonos="[RINCON_00011318566501400:volume]" }

Does anyone have this working?

Hi george, i also struggled for days and i read all i could find, the biggest problem i think is that that there often lack of complete codes throw all the config files…

here is my configs

openhab.cfg

################################ Sonos Binding ########################################

#Add a line for each Sonos device you want to pre-define
#The format is .udn=

sonos:saga.udn=RINCON_B8E937892FF401400
sonos:nova.udn=RINCON_B8E937892BEC01400
sonos:vrum.udn=RINCON_000E583B3E2001400
sonos:toa.udn=RINCON_000E58870C4401400

#Interval, in milliseconds, to poll the Sonos devices for status variables
sonos:pollingPeriod=1000

here is item

Switch Sonos_AA_saga_play “Play/Pause” (gAASonos) {sonos="[ON:saga:play], [OFF:saga:pause]"}
Switch Sonos_AA_saga_next “Next” (gAASonos) {sonos="[ON:saga:next]", autoupdate=“false”}
Switch Sonos_AA_saga_previous “Previous” (gAASonos) {sonos="[ON:saga:previous]", autoupdate=“false” }
Switch Sonos_AA_saga_mute “Mute” (gAASonos) {sonos="[ON:saga:mute], [OFF:saga:mute]", autoupdate=“true”}
Switch Sonos_AA_saga_stop “Stop” (gAASonos) {sonos="[ON:saga:stop], [OFF:saga:stop]", autoupdate=“true”}
Dimmer Sonos_AA_saga_vol “Volume” (gAASonos) {sonos="[saga:volume]" }
String Sonos_AA_saga_Track (gAASonos) {sonos="[saga:currenttrack]" }

and here is sitemap

sitemap defaultsitemap label=“xxxxxx”

{
Frame label=“Musik” {

	Text label="Saga" icon="speaker1" 
	{
	Switch item=Sonos_AA_saga_play 
	Switch item=Sonos_AA_saga_next
	Switch item=Sonos_AA_saga_previous
	Switch item=Sonos_AA_saga_mute
	Switch item=Sonos_AA_saga_stop
	Slider item=Sonos_AA_saga_vol
	Text item=Sonos_AA_saga_Track  label="Track: [%s]"
	
	}

i hope this can help u and others, there are still several things i havent gotten to work yet, like chosing radiostation and playlist.

1 Like

Hi. I also new into this. i tried to copy all the code from above, change the sonos same name, and stille enter the right udn number. but still i cang get it to work. Anyone who can help me :smile:

Peter

can u post the code u have.

Sonos name: saga

Sitemap:

sitemap defaultsitemap label=“xxxxxx”

{
Frame label=“Musik” {

Switch item=Play
Switch item=Stop
}

Items:

Switch Play {sonos="[ON:saga:play]"}
Switch Stop {sonos="
[ON:saga:stop]"}

Config:

#Add a line for each Sonos device you want to pre-define
#The format is .udn=

#sonos:saga.udn=RINCON_B8E937E56DF201400

#Interval, in milliseconds, to poll the Sonos devices for status variables
#sonos:pollingPeriod=1000

im a beginner just like u so im not sure im able to help, but i dont now what the * in your code is for, i dont have it try this
Switch Play {sonos="[ON:saga:play]"}
Switch Stop {sonos="[ON:saga:stop]"}

also if u only going to use 1 cmd it could be better to use mappings

Items:
Switch Play {sonos="[ON:saga:play]"}
Sitemap:
Switch item=Play mappings=[“ON”=“play”]

i guess u also running openhab in debug mode, so u should be able to se there whats happening, im also asuming the sonos addon is in the addons folder and that u can se it being loaded ?

Hi Chris

I now tried to copy your code into my files, but still nothing happening. First of all i would say, these codes is the only thing in the files nothing more. So its a verry clean setup with one Sonos play1

this is from the log:

23:34:41.764 [DEBUG] [.b.sonos.internal.SonosBinding:183 ] - Discovery started: Sonos, Inc. Sonos PLAY:1 S1
23:34:42.289 [INFO ] [.b.sonos.internal.SonosBinding:202 ] - Found a Sonos device (S1) with UDN uuid:RINCON_B8E937E56DF201400
23:34:46.859 [DEBUG] [.myopenhab.internal.MyOHClient:150 ] - Transport.EVENT_REQUEST_HEADERS
23:35:10.375 [DEBUG] [.b.sonos.internal.SonosBinding:318 ] - Executing command: item:Play, command:ON, ID:saga, CommandType:PLAY, commandString:ON

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

Does anybody understand this? I don’t.

Generic Item Binding Configuration

In order to bind an item to a Sonos Player, you need to provide configuration settings. The easiest way to do so is to add some binding information in your item file (in the folder configurations/items`). The syntax for the Sonos binding configuration string is explained here:

The format of the binding configuration is simple and looks like this:

sonos="[::], [::], …"

for Items that trigger action or commands on the Sonos Player, and

sonos="[:], [:], …"

for either Number or String Items that rather store a status variable or other from the Sonos Player

where the corresponds with the UDN (UPNP Unique Device Name) - or - the configuration in openhab.cfg where one can configure the Sonos players, which looks like this

sonos:.udn=[UDN]

and where is the command to be sent to the Sonos Player when is received. Some take input variables, which are taken from the current Item variable. In case status variables are used then any value received from the Sonos Player for the defined is used to update the Item

YAY! Success!

Thanks to an unrelated post where a Text String Command syntax was shown, I finally cracked it. I also had to upgrade my Sonos binding to 1.8 (I still run 1.7.0 runtime but it worked). DiningRoom is configured in openhab.cfg.

Resulting entries are as follows:

Items
Switch SonosPlayAlarmControl “Sonos Play Alarm"
String SonosDiningroom_PlayUri {sonos=”[DiningRoom:playuri]"}
String Sonosfavorite “Favorite [%s]” (Sonos) {sonos="[DiningRoom:favorite]", autoupdate=“false”}

Sitemap
Switch item=SonosPlayAlarmControl
Text item=Sonosfavorite

Rules
rule "Sonos Play Alarm"
when
Item SonosPlayAlarmControl received command ON
then
sendCommand(“Sonosfavorite” , “BurglarAlarm”)
end

BurglarAlarm is already set as a favorite in Sonos.

I tried a gazzilion versions using playuri but no matter what I tried I just couldn’t get my Sonos to find the file in question or I got permission denied errors. Sonos did recognise the file mostly but not the path. Must have tried at least 10 variations of syntax to get to my Windows PC running OH or my network drive. I gave up in the end, then realised I had the syntax for the String update. Simple when you know how but a devil when you don’t… I expect this can be used to open up a host of more complex Sonos operations under program control and can’t wait to get started :slightly_smiling:

See sendCommand(“Sonosfavorite” , “BurglarAlarm”) above. That was the key.

Cheers
Vitchling

hi vichling,

I have the same set-up and was wondering if you had any luck controlling a Sonos group.

Cheers,

Casper

Hi Casper

Yes, I achieved what I wanted.

Here are relevant items:

String SonosDiningroom_PlayUri {sonos="[DiningRoom:playuri]"}
String SonosAddKitchen {sonos="[DiningRoom:add]"}
String SonosAddDen {sonos="[DiningRoom:add]"}
String SonosAddMasterBedroom {sonos="[DiningRoom:add]"}
String SonosAddLivingRoom {sonos="[DiningRoom:add]"}
String Sonosradio {sonos="[DiningRoom:radio]"}
String currenttrack “CurrentTrack [%s]” (Sonos)
{sonos="[DiningRoom:currenttrack]", autoupdate=“false”}
String Sonosfavorite “Favorite [%s]” (Sonos) {sonos="[DiningRoom:favorite]",
autoupdate=“false”}
Switch PlayDiningRoom “Play/Pause” (Sonos)
{sonos="[ON:DiningRoom:play],[OFF:DiningRoom:pause]"}
Switch SonosPlayAlarmControl “Sonos Play Alarm"
Dimmer DiningRoomVolume “DiningRoom Volume [%d]”
{sonos=”[DiningRoom:volume]"}
Dimmer KitchenVolume “Kitchen Volume [%d]” {sonos="[Kitchen:volume]"}
Dimmer DenVolume “Den Volume [%d]” {sonos="[Den:volume]"}
Dimmer MasterBedroomVolume “My Bedroom Volume [%d]”
{sonos="[MasterBedroom:volume]"}
Switch AddAll

Here are the rules:

rule “NotAtHome”
//Tasker uses OpenhabOn and OpenhabOff Http POST commands, triggered by NFC
to switch alarms on and off
when
Item HouseAlarm changed from OFF to ON
then
notifyMyAndroid(“Alarm on”,“Bye!”)
sendCommand(AddAll, ON)
sendCommand(“Sonosfavorite”, “AlarmOn.wav”)
sendMail("tome@xyz.com", “Nichola - Alarm on”, “You’ve left the building”)
//Set AlarmTimer on for 5 minutes to avoid false triggers and false alarm
off switches
sendCommand(AlarmTimer, ON)
timer13 = createTimer(now.plusSeconds(300)) [|
sendCommand(“Sonosradio”, “BBC Radio 4”)
sendCommand(AlarmTimer, OFF)
]
postUpdate(Mqtt, 0)
if(HouseAlarm.state==ON) {
timer10 = createTimer(now.plusMinutes(120)) [|
if(HouseAlarm == ON) {
sendCommand(Heating, OFF)
}
]
} else {
if(timer10!=null) {
timer10.cancel
timer10 = null
}
}
end

rule "AtHome"
when
Item HouseAlarm changed from ON to OFF
then
notifyMyAndroid(“Alarm off”,“Welcome back!”)
sendCommand(AddAll, ON)
sendCommand(“Sonosfavorite” , “AlarmOff.wav”)
sendMail(tome@xyz.com, “Nichola - Alarm off”, “Welcome back!”)
postUpdate(Mqtt, 1)
sendCommand(Heating, ON)
end

rule "Sonos Add All Normal"
when
Item AddAll received command ON
then
sendCommand(“SonosAddKitchen”, “Kitchen”)
sendCommand(“SonosAddDen”, “Den”)
sendCommand(“SonosAddMasterBedroom”, “MasterBedroom”)
sendCommand(“SonosAddLivingRoom”, “LivingRoom”)
sendCommand(DiningRoomVolume, 50)
sendCommand(KitchenVolume, 50)
sendCommand(DenVolume, 50)
sendCommand(MasterBedroomVolume, 40)
end

rule “Sonos Fire Alarm” // groups all speakers, plays the alarm wav and
switches all lights on
when
Item FireAlarm received command ON
then
sendCommand(“SonosAddKitchen”, “Kitchen”)
sendCommand(“SonosAddDen”, “Den”)
sendCommand(“SonosAddMasterBedroom”, “MasterBedroom”)
sendCommand(“SonosAddDiningRoom”, “DiningRoom”)
sendCommand(DiningRoomVolume, 98)
sendCommand(KitchenVolume, 98)
sendCommand(DenVolume, 98)
sendCommand(MasterBedroomVolume, 98)
sendCommand(LandingLight, ON)
sendCommand(Output4, ON)
sendCommand(PorchLight, ON)
sendCommand(Dimm_1, 95)
sendCommand(Dimm_2, 95)
sendCommand(Dimm_3, 95)
sendCommand(Dimm_4, 95)
sendCommand(“Sonosfavorite” , “fire1.wav”)
end

rule "Sonos Play Burglar Alarm"
when
Item SonosPlayAlarmControl received command ON
then
sendCommand(“Sonosfavorite” , “BurglarAlarm”)
end

As you can see, I’m not a skilled programmer and I expect there’s a far more
elegant way of doing this. It may have bugs too - I haven’t tested all use
cases - just the fire alarm cases - so watch out. However, it seems to work
and that’s good enough for me. If you see any obvious bloopers, feel free to
let me know!

I’m using OH version 1.7.0 runtime but with the Sonos 1.8.0 binding. You
need to already have any Radio stations or sound files pre-loaded into Sonos
Favourites

Good luck!

Cheers
Vitchling

2 Likes