Sonos connect - AV receiver - best practices for turning receiver on-off + Vol

Hi,

I just bought a sonos connect or my AV receiver (i alread have 3 connect amps).
Now i’m wondering how you guys automate this?
I would like to turn the receiver on with a specific volume when i hit play on the sonos app.
And i would like to turn the receiver off with a specific volume when i hit stop/pause on the sonos app. with a delay maybe?
How do you handle when someone turns on the TV ans sonos is still playing? the volume must be very high for the sonos. because i control it from the app.

Thanks

Did you read the Sonos binding documentation?
You can create rules to change the volume when the Sonos gets a play of pause command.
Examples:

rule "Sonos in Bathroom via switch"
when
	Item Bathroom_Light_Scene changed
then
	if (Bathroom_Light_Scene.state == 20 || Bathroom_Light_Scene.state == 21){
		if (Bathroom_Sonos_LED.state == ON && (Bathroom_Sonos_Controller.state == PAUSE || Bathroom_Sonos_Controller.state == UNDEF)){
			Bathroom_Sonos_TuneIn.sendCommand(87683)
			Bathroom_Sonos_Volume.sendCommand(15)
		}else{
			Bathroom_Sonos_Stop.sendCommand(ON)
		}
	}
end
rule "Sonos LJ Qmusic"
when
	Item LJ_Presence changed to ON
then
	createTimer(now.plusMinutes(5), [| //wait if other prescence changed to ON
		if (Eva_Presence.state == OFF && Guests_Presence.state == OFF){
			LivingRoom_Sonos_Qmusic.sendCommand(ON)
		}
	])
end
rule "Sonos qmusic"
when
	Item LivingRoom_Sonos_Qmusic received command ON
then
	LivingRoom_Sonos_Standalone.sendCommand(ON)
	LivingRoom_Sonos_TuneIn.sendCommand(87683)
	LivingRoom_Sonos_Volume.sendCommand(13)
end

Example where I change the light with the TV is ON

rule "Auto Lights" 
when
	Item Dark_Outside changed or
	Item LivingRoom_Sonos_Linein changed or
	Item HouseMode changed to 0 or
	Item Current_TOD changed
then
	if (Dark_Outside.state == ON && Current_TOD.state != "NIGHT"){
		checkFirstS.apply(Shed_Light_OutSide_Switch,ON)
		createTimer(now.plusSeconds(5), [|
			val hue = ((now.getDayOfYear.intValue-1)*360/(if (now.getYear%4==0) 366 else 365)).toString
			if (LivingRoom_Sonos_Linein.state == ON){
    			LivingRoom_Light_LedBulb_Colors.sendCommand("0,100,100")
		    	LivingRoom_Light_LedBulb_Dimmers.sendCommand(100)
			}else {
				if (Current_TOD.state == "MORNING"){
					LivingRoom_Light_LedBulb_Colors.sendCommand("12,100,100")
				}else{
					LivingRoom_Light_LedBulb_Colors.sendCommand(hue+",100,100")
				}
				if (triggeringItem.name == "LivingRoom_Sonos_Linein"){
					LivingRoom_Light_LedBulb_Dimmers.sendCommand(75)
				} else {
					if (LivingRoom_Lights.state == OFF && HouseMode.state == 0){
						LivingRoom_Light_LedBulb_Dimmers.sendCommand(50)
					}	
				}
			}
		])
	}else{
		checkFirstS.apply(Shed_Light_OutSide_Switch,OFF)
		if (LivingRoom_Sonos_Linein.state == OFF || Dark_Outside.state != ON){
			checkFirstS.apply(LivingRoom_Light_LedBulb_Dimmers,OFF)
		}
	}
end

I’m totaly new to this and maybe it’s me ut the wiki is nog clear for me.
I tried the rule engine, it works for power on and volume change on state change of the sonos, but can’t get the input change to work.
So i might need to write a classic rule, but can’t seem to understand how to start.
I need some help.
i have:
SonosConnectMasterBedroom_State when this changes to PLAYING or ON?
Following should happen:

BEDROOMAVReceiverHC_Zone1_Power should change to ON
and
BEDROOMAVReceiverHC_Zone1_Volume should change to -15
and
BEDROOMAVReceiverHC_Zone1_InputSource should change to input 01

should it be like this?
make it a .rules file?

rule “SonosMB_on”
when
Item sonos:CONNECT:RINCON_949F3E2307CE01400:state == PLAYING
then
sendCommand(BEDROOMAVReceiverHC_Zone1_Power == ON)
sendCommand(BEDROOMAVReceiverHC_Zone1_InputSource == 01)
sendCommand(EDROOMAVReceiverHC_Zone1_Volume == -15)

end

No, this is not as it should be :slight_smile:
What is the name of your item of your Sonos Connect (how dit you name it in the item file?).
The rule will be:

 rule “SonosMB_on”
when
  Item **SonosItem** changed  to "PLAYING"
then
  BEDROOMAVReceiverHC_Zone1_Power.sendCommand(ON)
  BEDROOMAVReceiverHC_Zone1_InputSource.sendCommand("01")
  BEDROOMAVReceiverHC_Zone1_Volume.sendCommand(-15)
end

Replace **SonosItem** with the name of your item.

Ijsquare,

Thanks for your help, i’m at work now, i will try it this evening.
I seems i was completely wrong!
I hope it works, it would be fantastic!

Hello,
Just tried it

rule “SonosMB_on”
when
Item Sonos Masterbedroom changed to “PLAYING”
then
BEDROOMAVReceiverHC_Zone1_Power.sendCommand(ON)
BEDROOMAVReceiverHC_Zone1_InputSource.sendCommand(“01”)
BEDROOMAVReceiverHC_Zone1_Volume.sendCommand(-15)
end

Doesn’t work, get this rom the log file:

2019-10-04 17:46:44.487 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘SonosMB2.rules’
2019-10-04 17:46:44.499 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘SonosMB2.rules’ is either empty or cannot be parsed correctly!
2019-10-04 17:46:45.738 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘SonosMB2.rules’ has errors, therefore ignoring it: [1,7]: no viable alternative at input ‘�’

The item name can’t contain a space.

ok changed it, still no go!
Input seems to give error so i removed it, but still doesn’t work

rule “SonosMB_on”
when
Item SonosConnectMasterBedroom_State changed to “PLAYING”
then
BEDROOMAVReceiverHC_Zone1_Power.sendCommand(ON)
BEDROOMAVReceiverHC_Zone1_Volume.sendCommand(-15)
end

2019-10-04 21:18:35.369 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘SonosMB3.rules’
2019-10-04 21:18:35.386 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘SonosMB3.rules’ is either empty or cannot be parsed correctly!
2019-10-04 21:18:36.577 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘SonosMB3.rules’ has errors, therefore ignoring it: [1,6]: no viable alternative at input ‘�’

ok i found he problem
“SonosMB_on”
is diferent than
“SonosMB_on”

small detail but big difference!

this is the working rule
rule “SonosMB_on”
when
Item SonosConnectMasterBedroom_State changed to PLAYING
then
BEDROOMAVReceiverHC_Zone1_Power.sendCommand(ON)
BEDROOMAVReceiverHC_Zone1_InputSource.sendCommand(“01”)
BEDROOMAVReceiverHC_Zone1_Volume.sendCommand(-10)
end

rule “SonosMB_off”
when
Item SonosConnectMasterBedroom_State changed to STOPPED
then
BEDROOMAVReceiverHC_Zone1_InputSource.sendCommand(“05”)
BEDROOMAVReceiverHC_Zone1_Volume.sendCommand(-35)
end

So now it works quite wel, but i have a little issue.
When i change song or radio channel, the player states change to transition, and goes back to playing after that.
It means that the commands are ent again.
Not a big issue but not perfect.
Any idea if it possible to eliminate this?

Thanks