SONOS voulme adjustment using REGEX in rules

I am using openHAB version: 2.2.0-1 (Release Build)

Hi,
I have a SONOS system at home. In my Living room at the TV, i have a Playbase and Sub plus 2xPlay1 for a 5.1 systems. The feed is my Phillips TV via Optical audio connect.

My challenge is that if i play just music (streamed via Internet), the volume level at the Playbase is much higher then the TV feed into the SONOS system. Means if i stream music and then switch to TV the volume is incredible loud! Since SONOS has no solution my idea was to add SONOS to openhab which works really nice. Now the fun part:

I created a rule that if the “Current AV transport URI” is changed the volume should be adjusted. Here is my configurations:

item file

String			Sonos_WZPB_InputURI			"InputURI [%s]"						<status>			(Sonos)			{channel="sonos:zoneplayer:RINCON_12345612345601400:currenttransporturi"}

–> This rule fires when switching from audio straeming to TV (WORKS!)

rule file

rule "Sonos-WZ-Volume-tv"
when
  Item Sonos_WZPB_InputURI changed 
 then
  if(Sonos_WZPB_InputURI.state == 'x-sonos-htastream:RINCON_12345612345601400:spdif') {
  	  sendCommand(Sonos_WZPB_Volume, 12)
  }
end

–> now the switch back from the TV to audio streaming:

rule "Sonos-WZ-Volume-musik-1"
when
  Item Sonos_WZPB_InputURI changed 
 then
  if(Sonos_WZPB_InputURI.state == 'x-rincon-queue:RINCON_12345612345601400#0') {
  	  sendCommand(Sonos_WZPB_Volume, 3)
  }
end

This rule only fires if the string ends with #0 but if i try to trigger a radio playlist the match string changes after
RINCON_12345612345601400…

Example: x-rincon-mp3radio://http://listen.181fm.com/181-awesome80s_64k.aac
and all the other radio stations etc.

So my qeustion:
Is there a way to trigger the rule with a string starting

x-rincon-xyz

while xyz is a regex or open definition like a wildcard?
Or is there an easier way to do this since the string from tv - to audio is always different.

Many Thanks
Markus

Have you tried the .contains instead of equals?

Many Thanks that works, here my solution:

rule "Sonos-WZ-Volume-musik-1"
when
  Item Sonos_WZPB_InputURI changed 
 then
  if(Sonos_WZPB_InputURI.state.toString.contains = 'x-sonosapi-stream:') {
  	  sendCommand(Sonos_WZPB_Volume, 3)
  }
end

This filters all SONOS Streams - like radio stations.

:-):grinning:

1 Like