Hi all,
Relatively new to OpenHab - I’ve got the basics working, but have now started exploring some more complex rules. I’m trying to have a TV backlight (via hue binding) adjust it’s color based on the application running on the TV (detected via the LG WebOS binding).
So far I have this as the basic code:
rule "test"
when
Item Livingroom_TV_Power changed to ON or
Item Livingroom_TV_Application received update
then
var StringType application = new StringType(Livingroom_TV_Application.string)
logInfo("test.rules","TV application identified as:" +application)
var DecimalType hue = new DecimalType(0)
var PercentType sat = new PercentType(0)
var PercentType bright = new PercentType(0)
var PercentType temp = new PercentType(0)
switch (application) {
case com.webos.app.livetv:
hue = DecimalType(0)
sat = PercentType(0)
bright = PercentType(75)
temp = PercentType(100);
break;
case bbc:
hue = DecimalType(300)
sat = PercentType(100)
bright = PercentType(75)
temp = PercentType(0);
break;
case lovefilm:
hue = DecimalType(240)
sat = PercentType(100)
bright = PercentType(75)
temp = PercentType(0);
break;
case netflix:
hue = DecimalType(0)
sat = PercentType(100)
bright = PercentType(75)
temp = PercentType(0);
break;
case com.webos.app.hdmi2:
hue = DecimalType(120)
sat = PercentType(100)
bright = PercentType(75)
temp = PercentType(0);
break;
default:
hue = DecimalType(0)
sat = PercentType(0)
bright = PercentType(75)
temp = PercentType(100)
logWarn("test.rules","TV application not corrected, setting to default values")
break;
}
var HSBType light = new HSBType(hue,sat,bright)
sendCommand(Livingroom_TVBacklight_Temperature, temp)
sendCommand(Livingroom_TVBacklight_Color, light)
end
But I’m getting multiple errors in my log file, and the rule simply isn’t even being loaded (which makes debugging it challenging)
[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'test.rules' has errors, therefore ignoring it: [15,17]: no viable alternative at input '='
[15,19]: no viable alternative at input 'PercentType'
[15,30]: no viable alternative at input '('
[15,31]: extraneous input '0' expecting ')'
[16,20]: no viable alternative at input '='
[16,22]: no viable alternative at input 'PercentType'
[16,33]: no viable alternative at input '('
[16,34]: extraneous input '75' expecting ')'
[17,18]: no viable alternative at input '='
[17,20]: no viable alternative at input 'PercentType'
[17,31]: no viable alternative at input '('
[17,32]: extraneous input '100' expecting ')'
[17,36]: mismatched input ';' expecting '=>'
[18,18]: no viable alternative at input ';'
[19,9]: mismatched input 'case' expecting 'end'
It seems my syntax has gone badly wrong somehow, but I’m genuinely struggling to work out quite why it’s so unhappy?
Anyone with more java skills able to help point out my errors?
Thanks!