[Solved] Rules trying to learn

Trying hard to learn rules stuff.Want to make Sonos controller turn on reciever when playing.

rule "Sonos plays"

when
  Item sonos:CONNECT:RINCON_000E58AACE2201400:control == "Play"
then
  marantz_power.sendCommand(ON)
else
 marantz_power.sendCommand(OFF)
end

But it doesnt work…

Due to LOG errors i have changed to this
rule “Sonos plays”

when
  Item sonos:CONNECT:RINCON_000E58AACE2201400:control == "PLAY"
then
  marantz_power.sendCommand(ON) AND
  marantz_input.sendCommand(CD)
end

But still have error.

2020-03-08 15:39:51.486 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘hus.rules’ has errors, therefore ignoring it: [94,3]: no viable alternative at input ‘:’

Dont know what is wrong

Your triggering item looks like a channel? What is the name of the item?

If you are trying to use the channel then try:

Channel sonos:CONNECT:RINCON_000E58AACE2201400:control triggered PLAY

these are my reciever items

Switch marantz_power    "Receiver" <switch>         {channel="denonmarantz:avr:0006782c375f:general#power"}
Dimmer marantz_volume   "Volume"   <soundvolume>    {channel="denonmarantz:avr:0006782c375f:mainZone#volume"}
Number marantz_volumeDB "Volume [%.1f dB]"          {channel="denonmarantz:avr:0006782c375f:mainZone#volumeDBe"}
Switch marantz_mute     "Mute"     <mute>           {channel="denonmarantz:avr:0006782c375f:mainZone#mute"}
Switch marantz_z2power  "Zone 2"                    {channel="denonmarantz:avr:006782c375f:zone2#power"}
String marantz_input    "Input [%s]"                {channel="denonmarantz:avr:0006782c375f:mainZone#input" }
String marantz_surround "Surround: [%s]"            {channel="denonmarantz:avr:0006782c375f:general#surroundProgram"}
String marantz_command                              {channel="denonmarantz:avr:0006782c375f:general#command"}
1 Like

Where is the sonos item?

Player Sonos_stue_Controller   "Controller"                          (Sonos) {channel="sonos:CONNECT:stue:control"}
Dimmer Sonos_stue_Volume       "Volume [%.1f %%]" <soundvolume>      (Sonos) {channel="sonos:CONNECT:stue:volume"}
Switch Sonos_stue_Mute         "Mute"             <soundvolume_mute> (Sonos) {channel="sonos:CONNECT:stue:mute"}
Switch Sonos_stue_LED          "LED"              <switch>           (Sonos) {channel="sonos:CONNECT:stue:led"}
String Sonos_stue_CurrentTrack "Now playing [%s]" <text>             (Sonos) {channel="sonos:CONNECT:stue:currenttrack"}
String Sonos_stue_State        "Status [%s]"      <text>             (Sonos) {channel="sonos:CONNECT:stue:state"}

thx for the help btw

And what does your events.log show you happening to your Item?

Bad syntax - there are no == symbols in Item based triggers.
You perhaps want changed to

rule "Sonos plays"

when
Item Sonos_stue_Controller received update // or use changed to PLAY
then
    if(Sonos_stue_Controller.state == PLAY){
        marantz_power.sendCommand(ON) 
        marantz_input.sendCommand("CD") // not sure about the CD part??
}
end

I guess the last part should be marantz_input.sendCommand("CD"), it’s a string item after all.

CD is the name of the reciever input.

I edited the rule so give it a try and see what happens. Also try changed to PLAY if received update does not work.

@BDE

Could you please use “code fences” for better reading?

Thanks a lot.

e.g. your last post would look like:

Switch marantz_power    "Receiver"    {channel="denonmarantz:avr:0006782c375f:general#power"}
Dimmer marantz_volume   "Volume"      {channel="denonmarantz:avr:0006782c375f:mainZone#volume"}
Number marantz_volumeDB "Volume [%.1f dB]" {channel="denonmarantz:avr:0006782c375f:mainZone#volumeDBe"}
Switch marantz_mute     "Mute"        {channel="denonmarantz:avr:0006782c375f:mainZone#mute"}
Switch marantz_z2power  "Zone 2"      {channel="denonmarantz:avr:006782c375f:zone2#power"}
String marantz_input    "Input [%s]"  {channel="denonmarantz:avr:0006782c375f:mainZone#input" }
String marantz_surround "Surround: [%s]" {channel="denonmarantz:avr:0006782c375f:general#surroundProgram"}
String marantz_command                {channel="denonmarantz:avr:0006782c375f:general#command"}
1 Like

@BDE I see you have another post about rules. I recommend starting small with one or two items first. Then expand with more rules after you get a better understanding of how to write them.

Now it looks like this. No log errors ,but reciever doesnt turn on

when
Item Sonos_stue_Controller received update PLAY
then
    if(Sonos_stue_Controller.state == PLAY){
        marantz_power.sendCommand(ON) 
        marantz_input.sendCommand("CD")
}
end

@H102 Yes just realized that. One step at the time

@Celaeno1 DONE

1 Like

Did you try:

Item Sonos_stue_Controller changed to PLAY

Also, can you turn on the receiver via BasicUI to verify that it does work with OH?

yes and yes.

OK so the issue is with the trigger. What do you see in the logs for the sonos status when it changes? Please post the actual log.

ok

2020-03-08 16:35:04.084 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from PLAY to PAUSE

2020-03-08 16:35:05.520 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from PAUSE to UNDEF

2020-03-08 16:35:07.098 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from UNDEF to PLAY

2020-03-08 16:35:20.750 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_currentartist changed from Isam B to Burhan G

2020-03-08 16:35:20.755 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_currentalbum changed from Lost For Words to Pas På Pigerne

2020-03-08 16:35:20.757 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_currenttitle changed from Life to Nathalia

2020-03-08 16:35:20.762 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from PLAY to PAUSE

2020-03-08 16:35:21.011 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from PAUSE to UNDEF

2020-03-08 16:35:21.772 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_currentalbumart changed from raw type (image/jpeg): 52024 bytes to raw type (image/jpeg): 73920 bytes

2020-03-08 16:35:23.712 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from UNDEF to PAUSE

2020-03-08 16:35:23.941 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from PAUSE to UNDEF

2020-03-08 16:35:24.927 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from UNDEF to PLAY

2020-03-08 16:35:28.914 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from PLAY to PAUSE

2020-03-08 16:35:29.237 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from PAUSE to UNDEF

2020-03-08 16:35:29.860 [vent.ItemStateChangedEvent] - sonos_CONNECT_RINCON_000E58AACE2201400_control changed from UNDEF to PLAY