Problem with rule

Hi all

Hope someone can help me here.
After the latest OH update I have problems with a rule, the rule have been working perfect for the last 1/2 year.

I get this error now:

07:24:06.186 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Start Hue Colors fading in Triangle Window': An error occurred during the script execution: Couldn't invoke 'assignValueTo' for feature JvmVoid:  (eProxyURI: hue.rules#|::0.2.16.2.0.0.2.0.0::0::/1)

My rule look like this

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.joda.time.DateTime
var int percent = 0
var Timer fade_Timer1 = null
var Timer fade_Timer2 = null
var Timer fade_Timer3 = null
var Timer fade_Timer4 = null
var Timer fade_Timer5 = null
var Timer fade_Timer6 = null

----------------------------------------------------------------------------

rule "Start Hue Colors fading in Triangle Window"

 when 
  
  Item smarthouse_lux changed from OFF to ON
  or
  Item Light4_ON changed from OFF to ON
  or
  Item Light4_Toggle changed from OFF to ON
  or
  Item Light5_ON changed from OFF to ON
   
 then

    if (smarthouse_lux.state == ON) {
    var Timer timer = null
    // set a timer to sligtly change the color again and again
    timer = createTimer(now, [|
      Hue_Fade_Next.sendCommand(now.toString)
      if (timer != null) {
        timer.reschedule(now.plusSeconds(10))
      }
    ])			
  }
  else {
    timer = null
  }
end

// Fade a bit. 
rule "Hue Fade Next"
  when 
    Item Hue_Fade_Next changed
  then
    if (smarthouse_lux.state == ON) {
      // get your current color
      var hsb = Light4_Color.state as HSBType
      // change it a little bit
      var DecimalType hue = new DecimalType(hsb.hue.intValue % 360 + 1) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
      var PercentType sat = new PercentType(hsb.saturation.intValue) // 0-100
      var PercentType bright = new PercentType(100) // 0-100 (hsb.brightness.intValue)
      var PercentType bright1 = new PercentType(40) // 0-100 (hsb.brightness.intValue)
      var HSBType newHsb = new HSBType(hue,sat,bright)	
      var HSBType newHsb1 = new HSBType(hue,sat,bright1)	
      Light4_Color.send(newHsb)
      Light5_Color.send(newHsb1)
    }	
 
   
      		
end

Romove or mark as comment “-----”

if (timer != null) {
timer.reschedule(now.plusSeconds(10))

Cannot refer to the non-final variable timer inside a lambda expression

I still get that error

What have you changed in the timer-statement? Post the actuell code please.

I commented out the variable timer


 when 
  
  Item smarthouse_lux changed from OFF to ON
  or
  Item Light4_ON changed from OFF to ON
  or
  Item Light4_Toggle changed from OFF to ON
  or
  Item Light5_ON changed from OFF to ON
   
 then

    if (smarthouse_lux.state == ON) {
    var Timer timer = null
    // set a timer to sligtly change the color again and again
    timer = createTimer(now, [|
      Hue_Fade_Next.sendCommand(now.toString)
//      if (timer != null) {
//        timer.reschedule(now.plusSeconds(10))
//      }
    ])			
  }
  else {
    timer = null
  }
end

// Fade a bit. 
rule "Hue Fade Next"
  when 
    Item Hue_Fade_Next changed
  then
    if (smarthouse_lux.state == ON) {
      // get your current color
      var hsb = Light4_Color.state as HSBType
      // change it a little bit
      var DecimalType hue = new DecimalType(hsb.hue.intValue % 360 + 1) // 0-360; 0=red, 120=green, 240=blue, 360=red(again)
      var PercentType sat = new PercentType(hsb.saturation.intValue) // 0-100
      var PercentType bright = new PercentType(100) // 0-100 (hsb.brightness.intValue)
      var PercentType bright1 = new PercentType(40) // 0-100 (hsb.brightness.intValue)
      var HSBType newHsb = new HSBType(hue,sat,bright)	
      var HSBType newHsb1 = new HSBType(hue,sat,bright1)	
      Light4_Color.send(newHsb)
      Light5_Color.send(newHsb1)
    }

For the

  else {
    timer = null

the

    var Timer timer = null

must be outside the if-statement.
If this don’t help, post the 4 in the rule used items please.

Hi :slight_smile:

I have tried what you are suggesting, the error disappeared but I don’t think I made the correct move of the timer outside the if-statement.

Would you be able to help me with the correct way to code this ?

Nanna,

  • Can you paste your code into the Eclipse Smarthome Designer and check if there are any errors coming up and to make sure you don’t have syntax error?
  • Can you add logInfo-Statements to the respective locations in the code to debug the functionality and then look into the log file (yoururl:9001) for the log output?

cheers
Stefan

For the timer variable to be accessible each time the script runs, you will need it to be a global variable. Move it’s instantiation to the very top of the rule file (outside of the rule).

Take a look in the first post here for an example.

[PS, Eclipse Smarthome Designer has been discontinued. Use VS Code with the OH extension instead.]

Thanks all, for your help :slight_smile:

It works perfect again.