Hue light brightness is set back to '1' seconds after turning it on

Hi,

Got a strange situation going on with the Hue bulbs.
I have a rule to switch them all on when it gets dark, all goes well exept , every now and then one of the lights switches back to a brightness level of ‘1’ seconds after it has been set to e.g. ‘30’. I never set a value ‘1’ anywhere in my rules.

I’am running the latest stable versiob of openhabian:

  • openhab2 is already the newest version (2.4.0-1).

2019-03-16 08:28:45.440 [vent.ItemStateChangedEvent] - Woonkamer_Lamp_Kastje changed from 0 to 30
:
:
40
2019-03-16 08:28:51.610 [vent.ItemStateChangedEvent] - Woonkamer_Lamp_Kastje changed from 30 to 1

I am logging also from the rule and the it really sets only once the ‘Woonkamer_Lamp_Kastje’ to 30, not 1

2019-03-16 08:28:45.366 [WARN ] [se.smarthome.model.script.lightmode2] - devname:Woonkamer_Lamp_Kastje
2019-03-16 08:28:45.369 [WARN ] [se.smarthome.model.script.lightmode2] - devstate:0
2019-03-16 08:28:45.393 [WARN ] [se.smarthome.model.script.lightmode2] - chkdevname:
2019-03-16 08:28:45.400 [WARN ] [se.smarthome.model.script.lightmode2] - level=30

here are the rules:

// constants
val Number threshold_indoor_on = 300
val Number threshold_indoor_off = 400
val Number threshold_outdoor_on = 25
val Number threshold_outdoor_off = 50

rule “autolights”
when
Time cron “0/10 * * ? * * *” // every 10 sec
then
//logWarn(“autolights”, “rule started”)

  //var Number lvl = TestLevel.state as Number
  //var Number lvl_prev = TestPrevLevel.state as Number

  var Number lvl = Serre_lightlevel.state as Number
  var Number lvl_prev = 0 

  // first start 'Serre_lightlevel_Prev' will have NULL value
  if (Serre_lightlevel_Prev.state == NULL ){
    lvl_prev = lvl
  }
  else{
    lvl_prev = Serre_lightlevel_Prev.state as Number
  }

   //logWarn("autolights", "lvl="+lvl.toString)
   //logWarn("autolights", "lvl_prev="+lvl_prev.toString)
   
   //indoor
   if (lvl < threshold_indoor_on && lvl_prev >= threshold_indoor_on){
     logWarn("autolights", "lvl="+lvl.toString)
     logWarn("autolights", "lvl_prev="+lvl_prev.toString)
     logWarn("autolights", "Turn on lights in house")
     LightMode.sendCommand(1)
   }

   if (lvl > threshold_indoor_off && lvl_prev <= threshold_indoor_off){
     logWarn("autolights", "lvl="+lvl.toString)
     logWarn("autolights", "lvl_prev="+lvl_prev.toString)
     logWarn("autolights", "Turn off lights in house")
     LightMode.sendCommand(0)
   }

   //outdoor
   if (lvl < threshold_outdoor_on && lvl_prev >= threshold_outdoor_on){
     logWarn("autolights", "Turn on lights in garden")
     GTuinLights.members.forEach [ item | item.sendCommand(ON)]
   }

   if (lvl > threshold_outdoor_off && lvl_prev <= threshold_outdoor_off){
     logWarn("autolights", "Turn off lights in garden")
     GTuinLights.members.forEach [ item | item.sendCommand(OFF)]
   }
   
   //keuken
   val state = Keuken_Beweging_Switch_alarm_motion.state
   if (state == ON && lvl < threshold_indoor_on && lvl_prev >= threshold_indoor_on){
     GKeukenLights.members.forEach [ item | item.sendCommand(ON)]
   }

   Serre_lightlevel_Prev.sendCommand(lvl)
   //TestPrevLevel.sendCommand(lvl)
   //logWarn("autolights", "rule ended")

end

val cfg = ’
{
“dev”: [
{
“name”: “Woonkamer_Lamp_Muur_Bank”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“75”},
{“mode”:7, “level”:“60”}
]
},
{
“name”: “Woonkamer_Lamp_Muur_TV”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“75”},
{“mode”:7, “level”:“60”}
]
},
{
“name”: “Woonkamer_Lamp_IKEA1”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“77”},
{“mode”:7, “level”:“60”}
]
},
{
“name”: “Woonkamer_Lamp_IKEA2”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“77”},
{“mode”:7, “level”:“60”}
]
},
{
“name”: “Woonkamer_Lamp_IKEA3”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“77”},
{“mode”:7, “level”:“60”}
]
},
{
“name”: “Woonkamer_Lamp_Zijraam1”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“70”},
{“mode”:7, “level”:“70”}
]
},
{
“name”: “Woonkamer_Lamp_Zijraam2”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“70”},
{“mode”:7, “level”:“70”}
]
},{
“name”: “Woonkamer_Lamp_Zijraam3”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“OFF”},
{“mode”:1, “level”:“70”},
{“mode”:7, “level”:“70”}
]
},
{
“name”: “Woonkamer_Lamp_Kastje”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“0”},
{“mode”:1, “level”:“30”},
{“mode”:7, “level”:“0”}
]
},
{
“name”: “Woonkamer_Lamp_Plant”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“0”},
{“mode”:1, “level”:“50”},
{“mode”:7, “level”:“0”}
]
},
{
“name”: “Livingroom_TVbias_Level”,
“check_dev”:“TV_Woonkamer”,
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“0”},
{“mode”:1, “level”:“0”, “check_dev_state”:“OFF”},
{“mode”:1, “level”:“10”, “check_dev_state”:“ON”},
{“mode”:7, “level”:“0”, “check_dev_state”:“OFF”},
{“mode”:7, “level”:“10”, “check_dev_state”:“ON”},
]
},
{
“name”: “Livingroom_Fireplace_Level”,
“check_dev”:"",
“check_on”:"",
“check_off”:"",
“levels”: [
{“mode”:0, “level”:“0”},
{“mode”:1, “level”:“20”},
{“mode”:7, “level”:“0”}
]
}
]
}

rule “LightMode”
when
Item LightMode received command
then
logWarn(“lightmode”, “start”)

            var oldmode = LightMode.state as Number
            var newmode = receivedCommand
            logWarn("lightmode", "old mode="+oldmode.toString)
            logWarn("lightmode", "new mode="+newmode.toString)
            
            //loop devices in config
            val len = Integer.parseInt(transform("JSONPATH", "$.dev.length()", cfg))
            for (var int i = 0 ; i < len ; i++) {
               logWarn("lightmode2", "----------")

               val s = Integer.toString(i)

               // check if we need to control the device based on 'check_on' / 'check_off' settings
               var _continue = true 

              if (newmode>0){
                  val String check_on_dev = transform("JSONPATH", "$.dev["+s+"].check_on", cfg)
                  if (check_on_dev != ""){
                    logWarn("lightmode2", "check_on_dev:"+check_on_dev)
                    val check_on = GAutoLightSettings.allMembers.filter[d |d.name.equals(check_on_dev)].head
                    val check_on_dev_state = check_on.state
                    logWarn("lightmode2", "check_on_dev_state:"+check_on_dev_state.toString())
                    _continue = (check_on.state == ON)
                  }
              }

              if (newmode==0){   
                  val String check_off_dev = transform("JSONPATH", "$.dev["+s+"].check_off", cfg)
                  if (check_off_dev != ""){
                    logWarn("lightmode2", "check_off_dev:"+check_off_dev)
                    val check_off = GAutoLightSettings.allMembers.filter[d |d.name.equals(check_off_dev)].head
                    val check_off_dev_state = check_off.state
                    logWarn("lightmode2", "check_off_dev_state:"+check_off_dev_state.toString())
                    _continue = (check_off.state == ON)
                  }
              }

               if ( _continue ){
                  val String devname = transform("JSONPATH", "$.dev["+s+"].name", cfg)
                  //logWarn("lightmode2", "members: "+GWoonkamer.allMembers.toString())
                  val dev = GWoonkamer.allMembers.filter[d |d.name.equals(devname)].head
                  val dev_state = dev.state                   

                  logWarn("lightmode2", "devname:"+devname)
                  logWarn("lightmode2", "devstate:"+dev_state) 

                  val String chkdevname = transform("JSONPATH", "$.dev["+s+"].check_dev", cfg)
                  val check_dev = GWoonkamer.allMembers.filter[d |d.name.equals(chkdevname)].head
                  logWarn("lightmode2", "chkdevname:"+chkdevname)
        
                  var level = ""
                  if (chkdevname == ""){
                    level = transform("JSONPATH", "$.dev["+s+"].levels[?(@.mode == "+newmode+")].level", cfg)   
                  }
                  else{
                    // we need to take the chk device into account
                    var chkdev_state = check_dev.state  
                    logWarn("lightmode2", "check_dev_state:"+chkdev_state)
                    logWarn("lightmode2", "JSONPATH: "+"$.dev["+s+"].levels[?(@.mode == "+newmode+" && @.check_dev_state == '"+chkdev_state.toString()+"')].level")
                    level = transform("JSONPATH", "$.dev["+s+"].levels[?(@.mode == "+newmode+" && @.check_dev_state == '"+chkdev_state.toString()+"')].level", cfg)     
                    
                    //if not found we can take the value without the device
                    if (level == "NULL"){
                      level = transform("JSONPATH", "$.dev["+s+"].levels[?(@.mode == "+newmode+")].level", cfg)
                    }
                  }
                  
                  logWarn("lightmode2", "level="+level)
                  
                  dev.sendCommand(level)
               }
            }
          
            logWarn("lightmode", "end")

end