Issue with "working" rule

Hi all

I have a rule where my Sonos turn on my reciever ,when Sonos start playing.

Althought rule work , i still need some minor changes.

It looks like this now.

rule "Sonos plays"
when
Item Sonos_stue_Controller changed
then
    if(Sonos_stue_Controller.state == PLAY){
       marantz_power.sendCommand(ON) 
       createTimer(now.plusSeconds(10)) [| marantz_input.sendCommand("CD")  ]      
       createTimer(now.plusSeconds(10))  [|marantz_volume.sendCommand(35) ]
       createTimer(now.plusSeconds(10))  [|Sonos_stue_Controller.sendCommand(PLAY) ]
           }
end

My issue is IF Reciever is already ON and on another input when activating Sonos ,rule doesn’t work.

I am considering just turning reciever off ,before on ,but i am looking for better suggestions.

Any suggestions ?

Why don’t you check if the receiver is already ON

would that be something like this

rule "Sonos plays"
when
Item Sonos_stue_Controller changed
then
    if(Sonos_stue_Controller.state == PLAY)
       if(marantz_power.state == ON){
       createTimer(now.plusSeconds(1))  [| marantz_input.sendCommand("CD")  ]      
       createTimer(now.plusSeconds(1))  [|marantz_volume.sendCommand(35) ]
       createTimer(now.plusSeconds(1))  [|Sonos_stue_Controller.sendCommand(PLAY) ]
           }
       else if(marantz_power.state == OFF){
       createTimer(now.plusSeconds(10))  [| marantz_input.sendCommand("CD")  ]      
       createTimer(now.plusSeconds(10))  [|marantz_volume.sendCommand(35) ]
       createTimer(now.plusSeconds(10))  [|Sonos_stue_Controller.sendCommand(PLAY) ]
	      }

end

well no errors in log ,but seems to not work

Try to set you want to see in the log what it does

logInfo("Sonos switch","Marantz_power "+ marantz_power.state)

Looks like you’re forgetting to switch on your marantz when it’s currently off.

try this:

rule "Sonos plays"
when
  Item Sonos_stue_Controller changed
then
  if(Sonos_stue_Controller.state == PLAY) {
    if(marantz_power.state == ON) {
      createTimer(now.plusSeconds(1))  [| marantz_input.sendCommand("CD")  ]      
      createTimer(now.plusSeconds(1))  [|marantz_volume.sendCommand(35) ]
      createTimer(now.plusSeconds(1))  [|Sonos_stue_Controller.sendCommand(PLAY) ]
    } else if(marantz_power.state == OFF) {
      marantz_power.sendCommand(ON)
      createTimer(now.plusSeconds(10))  [| marantz_input.sendCommand("CD")  ]      
      createTimer(now.plusSeconds(10))  [|marantz_volume.sendCommand(35) ]
      createTimer(now.plusSeconds(10))  [|Sonos_stue_Controller.sendCommand(PLAY) ]
    }
  }
end
1 Like

yes i realized t hat before you wrote it ,but you also found my missing }
.
Works now thanks.

Same rule, less complicated:

rule "Sonos plays"
when
  Item Sonos_stue_Controller changed to PLAY
then
  var timerSec = 1

  if(marantz_power.state == OFF) {
    marantz_power.sendCommand(ON)
    timerSec = 10
  }

  createTimer(now.plusSeconds(timerSec)) [| marantz_input.sendCommand("CD")  ]      
  createTimer(now.plusSeconds(timerSec)) [|marantz_volume.sendCommand(35) ]
  createTimer(now.plusSeconds(timerSec)) [|Sonos_stue_Controller.sendCommand(PLAY) ]
end

help very appriciated .

I have another one i need to fine tune.

it when alarm is off it activates power outlets…(group)

Looks like this.

rule "Alarm deaktiveret"

when
Item Alarm_tilstand changed
then
    if(Alarm_tilstand.state == ON){
        gudtag.sendCommand(ON) 
              }

end

Issue is house automation is turning outlets off during the night ( not Openhab)

So i need to reactivate in the morning.

Any suggestions…

use CRON or (maybe better): install and use the astro binding as rule trigger. so:

rule "Alarm deaktiveret"
when
  Item Alarm_tilstand changed to ON or
  Time cron "0 0 7 1/1 * ? *" // Every day at 07:00am
then
  if (Alarm_tilstand.state == ON) gudtag.sendCommand(ON)
end

or (https://www.openhab.org/addons/bindings/astro/)

rule "Alarm deaktiveret"
when
  Item Alarm_tilstand changed to ON or
  Channel 'astro:sun:home:rise#event' triggered START // Every day at sunrise
then
  if (Alarm_tilstand.state == ON) gudtag.sendCommand(ON)
end

thx alot i will definately try it out…

why would you prefer astro …(just trying to learn)

I have astro installed…

It all depends on your requirements. If the purpose is lighting, then using the astro binding is much more dynamic then cron. That’s because, for example, in summer you want lights to turn on at a different time then in winter. But if it’s all about wall outlets which just need to turn on at a certain static time throughout the whole year then cron might be sufficient.

ok thx again.

Very appriciated…

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.