I am moving to OH2 from OH1 and one of my rules no longer works

Any idea where I am going wrong? Missing an import maybe?

"
rule "Lamps On"
when

Item BR_Scene changed to "LMPS"

then   
    
	logInfo("Rules", "Running: BR_Scene change -> LMPS")
	var DecimalType hue = new DecimalType(65) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
	var PercentType sat = new PercentType(50) // 0-100
	var PercentType bright = new PercentType(100) // 0-100

	var HSBType light = new HSBType(hue,sat,bright)
      
       sendCommand(CHCB606, light)
       sendCommand(CHCB804, light)
  	   sendCommand(SHCB805, OFF)
       sendCommand(SHCB806, OFF)
end

rule "Lamps Dim"
when

Item BR_Scene changed to "LMPSD"

then   
    
	logInfo("Rules", "Running: BR_Scene change -> LMPSD")   
	var DecimalType hue = new DecimalType(65) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
	var PercentType sat = new PercentType(50) // 0-100
	var PercentType bright = new PercentType(50) // 0-100

	var HSBType light = new HSBType(hue,sat,bright)

		sendCommand(CHCB606, light)
        sendCommand(CHCB804, light)
        sendCommand(SHCB805, OFF)
        sendCommand(SHCB806, OFF)

end

rule "Bedroom Dim"
when

Item BR_Scene changed to "Dim"

then   
	
	logInfo("Rules", "Running: BR_Scene change -> Dim")
	var DecimalType hue = new DecimalType(65) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
	var PercentType sat = new PercentType(50) // 0-100
	var PercentType bright = new PercentType(50) // 0-100

	var HSBType light = new HSBType(hue,sat,bright)
      
       sendCommand(CHCB606, light)
       sendCommand(CHCB804, light)
       sendCommand(CHCB805, light)
       sendCommand(CHCB806, light)
  
end

rule "Bedroom All On"
when

Item BR_Scene changed to "AON"

then   
	
	logInfo("Rules", "Running: BR_Scene change -> AON")
	var DecimalType hue = new DecimalType(65) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
	var PercentType sat = new PercentType(50) // 0-100
	var PercentType bright = new PercentType(100) // 0-100

	var HSBType light = new HSBType(hue,sat,bright)
      
       sendCommand(CHCB606, light)
       sendCommand(CHCB804, light)
       sendCommand(CHCB805, light)
       sendCommand(CHCB806, light)
  
end

rule "Bedroom All Off"
when

Item BR_Scene changed to "OFF"

then   
	   logInfo("Rules", "Running: BR_Scene change -> OFF")
       sendCommand(SHCB606, OFF)
       sendCommand(SHCB804, OFF)
       sendCommand(SHCB805, OFF)
       sendCommand(SHCB806, OFF)
       sendCommand(Dimmer_BR_Fan, 0)
  	   sendCommand(BR_Activity, "PowerOff")
  	   sendCommand(Outlet_BR_1, OFF)
  
end

rule "Lamps Off"
when   

Item BR_Scene changed to "LOFF"

then   
       
	   logInfo("Rules", "Running: BR_Scene change -> LOFF")
	   sendCommand(SHCB606, OFF)
       sendCommand(SHCB804, OFF)
end

rule "Bedtime (ZZZZzzZzz)"
when   

Item BR_Scene changed to "ZZZ"

then   
	   
	   logInfo("Rules", "Running: BR_Scene change -> ZZZ")
       sendCommand(SHCB606, OFF)
       sendCommand(SHCB804, OFF)
       sendCommand(SHCB805, OFF)
       sendCommand(SHCB806, OFF)
       sendCommand(Dimmer_BR_Fan, 100)
       sendCommand(BR_Activity, 19998758)
       sendCommand(Outlet_BR_1, ON)
       
       Thread::sleep(3000)
  
  	   sendCommand(SHCB606, OFF)
       sendCommand(SHCB804, OFF)
       sendCommand(SHCB805, OFF)
       sendCommand(SHCB806, OFF)
       sendCommand(Dimmer_BR_Fan, 100)
       sendCommand(BR_Activity, 19998758)
       sendCommand(Outlet_BR_1, ON)
  
end

    
    
    rule "Lamps on with Fan on Med"    
    when
    
    Item BR_Scene changed to "LFM"

then   
	
	logInfo("Rules", "Running: BR_Scene change -> LFM")
	var DecimalType hue = new DecimalType(65) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
	var PercentType sat = new PercentType(50) // 0-100
	var PercentType bright = new PercentType(100) // 0-100

	var HSBType light = new HSBType(hue,sat,bright)
      
       sendCommand(CHCB606, light)
       sendCommand(CHCB804, light)
       sendCommand(Dimmer_BR_Fan, 50)
  
end

       rule "Lamps on with Fan on Med"    
    when
    
    Item BR_Scene changed to "LFH"

then   

	logInfo("Rules", "Running: BR_Scene change -> LFH")
	var DecimalType hue = new DecimalType(65) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
	var PercentType sat = new PercentType(50) // 0-100
	var PercentType bright = new PercentType(100) // 0-100

	var HSBType light = new HSBType(hue,sat,bright)
      
       sendCommand(CHCB606, light)
       sendCommand(CHCB804, light)
       sendCommand(Dimmer_BR_Fan, 100)
  
end

"

First, fix your code fences. Second, you mentioned “one” of your rules is not working but you posted several rules. Which of these rules is not working properly?

I think the reason it’s not working is that the changed to [String] doesn’t work for String items on OH2. You have to use just changed as trigger and write some logic in the rules to check the state.

Not to forget, you could easily build one rule:

rule "BR_Scene changed"
when
    Item BR_Scene changed
then
    var DecimalType hue
    var DecimalType sat
    var DecimalType bright
    var HSBType light
    switch BR_Scene.state.toString {
        case "LMPS" : {
            // set vars, sendCommand, log ...
        }
        case "LMPSD" : {
            // set vars, sendCommand, log ...
        }
        case "Dim" : {
            // set vars, sendCommand, log ...
        }
        ...
        case default : {
            logInfo ("Rules","BR_Scene has unknown value {}",BR_Scene.state.toString)
        }
    }
end

Apologies, they are all in 1 rules file. You are correct they are multiple rules. This is my first time posting code. I will have to figure out the fences.

Thanks Udo! I will see if I can get this going as it is also way more efficient.

A

We are back up and running. Thank you gentlemen…

A

I do get this in the log every time I reload rules, but they seem to work…

Configuration model ‘<RULEFILE.RULES>’ is either empty or cannot be parsed correctly!

Any thoughts?

A