Problem with simple rule for light dimming

Hello OH Community,
I have a rule for dimming my light with a switch, in general it’s working. But sometimes it doesn’t.

These messages appear sometimes in my log:

2017-11-02 21:22:16.008 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'LED Strip higher': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(T,org.eclipse.xtex
t.xbase.lib.Procedures$Procedure1) on instance: null
2017-11-02 21:22:23.095 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'LED Strip higher': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(T,org.eclipse.xtex
t.xbase.lib.Procedures$Procedure1) on instance: null

This is my rule

rule "LED Strip higher"
when
        Item Switch_Livingroom_C2_Short changed to ON
then
        if ((Light_Livingroom_LEDStrip_brightness.state as DecimalType) => 80) {
                Light_Livingroom_LEDStrip_brightness.sendCommand(100)
        } else {
                Light_Livingroom_LEDStrip_brightness.sendCommand((Light_Livingroom_LEDStrip_brightness.state as DecimalType) + 20)
        }
end

Item Definition:

Dimmer  Light_Livingroom_LEDStrip_brightness            "LED Leiste Helligkeit [%d%%]"          <slider>        (gLivingroom,gMiLight)  { channel="milight:whiteLed:ACCFXXXXXXXX:0:ledbrightness" }
Switch Switch_Livingroom_C2_Short               "Stuben Licht-Taster oben kurz"                                 <wallswitch>    (gLivingroom)                           { channel="homematic:HG-HM-PB-2-WM55-2:homegear:XXXXXXXXXX:2#PRESS_SHORT" }

Does someone know whats wrong with this simple rule?

Thanks in advance! :slight_smile:

Ozzy

Try logging some info first (check the karaf console for output) and get the state value before sending the command, like this:

rule "LED Strip higher"
when
        Item Switch_Livingroom_C2_Short changed to ON
then
        logInfo("LEDStripStateInfo", Light_Livingroom_LEDStrip_brightness.state.toString)
        if ((Light_Livingroom_LEDStrip_brightness.state as DecimalType) => 80) {
                Light_Livingroom_LEDStrip_brightness.sendCommand(100)
        } else {
                var int tempLEDvalue=(Light_Livingroom_LEDStrip_brightness.state as DecimalType).intValue
                Light_Livingroom_LEDStrip_brightness.sendCommand(tempLEDvalue + 20)
        }
end

Good point, added some more log messages :slight_smile:

Will come back with some results

Check the state is not NULL before trying to add 20 to it. See if that makes a diff

My modified rule:

rule "LED-Strip brightness increase"
when
        Item Switch_Livingroom_C2_Short changed to ON
then
        logDebug(filename, "LED-Strip brightness increase triggered - current brightness state: {}", Light_Livingroom_LEDStrip_brightness.state)
        if ((Light_Livingroom_LEDStrip_brightness.state as DecimalType) => 80) {
                logDebug(filename, "Brightness state higher-equal 80: {}", Light_Livingroom_LEDStrip_brightness.state)
                if (Light_Livingroom_LEDStrip_brightness.state != NULL)
                        Light_Livingroom_LEDStrip_brightness.sendCommand(100)
                else
                        logDebug(filename, "WARNING: Light_Livingroom_LEDStrip_brightness.state is NULL")
        } else {
                logDebug(filename, "Brightness state lower-equal 80: {}", Light_Livingroom_LEDStrip_brightness.state)
                var tempLEDValue = (Light_Livingroom_LEDStrip_brightness.state as DecimalType).intValue
                logDebug(filename, "Brightness state: {}", tempLEDValue)
                if (Light_Livingroom_LEDStrip_brightness.state != NULL)
                        Light_Livingroom_LEDStrip_brightness.sendCommand((Light_Livingroom_LEDStrip_brightness.state as DecimalType) + 20)
                else
                        logDebug(filename, "WARNING: Light_Livingroom_LEDStrip_brightness.state is NULL")
        }
end

Error does still occur:

2017-11-08 19:44:10.642 [DEBUG] [.model.script.livingroom_light.rules] - LED-Strip brightness increase triggered - current brightness state: 50
2017-11-08 19:44:10.654 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'LED-Strip brightness increase': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(T,org.eclipse.xtext.xbase.lib.Procedures$Procedure1) on instance: null
2017-11-08 19:44:13.170 [DEBUG] [.model.script.livingroom_light.rules] - LED-Strip brightness increase triggered - current brightness state: 50
2017-11-08 19:44:13.184 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'LED-Strip brightness increase': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(T,org.eclipse.xtext.xbase.lib.Procedures$Procedure1) on instance: null

Any ideas/advises? :confused:

Shouldn’t that be >= and not => ?

Ahh maybe that’s my problem, I fixed it and will report :slight_smile:

What r u using to write with?
Eclipse smart home designer will let u know when u have syntax errors like the above and also if u use Ctrl space bar it will also suggest code.

I’m using vi because I’m already familiar with some comfortable shortcuts. I will try to use Designer in the future to check my rules.

My rules is now working perfectly, problem solved.

Thanks for the support!