Request current state of hue lightstrip

Hello,

I want to use a single button switch to turn on/off a hue lightstrip.

Actually its possible to control lightstrip with follow commands:

sendCommand(Lightstrip_ColorTemperature, ON) 
sendCommand(Lightstrip_ColorTemperature, OFF)

But now i need to request the state to change between on and off. but it’s not possible to get the state. i try Lightstrip_ColorTemperature.state or Lightstrip_ColorTemperature.state.brightness but i only get eclipse errors as result:

logError("Room2.LightStrip", Lightstrip_ColorTemperature.state)

==> /var/log/openhab2/openhab.log <==
2018-04-30 21:41:27.773 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Xiaomi Aqara Battery Powered 1 Button Switch 2’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logError(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

logError("Room2.LightStrip", (Lightstrip_ColorTemperature.state as HSBType).brightness)

==> /var/log/openhab2/openhab.log <==
2018-04-30 21:56:29.895 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Xiaomi Aqara Battery Powered 1 Button Switch 2’: Could not cast 0 to org.eclipse.smarthome.core.library.types.HSBType; line 141, column 38, length 56

i assume Lightstrip_ColorTemperature is a item of type dimmer and you have also a item called Lightstrip_Color of type color

if so, you have two options:

  1. creating a switch for Lightstrip_Color, in PaperUI when creating the item you can select number or switch when creating the item, you can have both at the same time, and just check the stat of that switch

or

  1. using a rule, i think this one should work
rule "Lightstrip_Color on/off"
 when
   Item Lightstrip_Color changed
 then
   var buffer = Lightstrip_Color.state.toString.split(",")
   var value = Integer.parseInt(buffer.get(2))   
   logWarn("myLog", value.toString)
   if ((value as Number) == 0) {
     logError("Room2.LightStrip", "light is off, Brightness:"+value.toString)
   }
   if ((value as Number) > 0) {
     logError("Room2.LightStrip", "light is off, Brightness:"+value.toString)
  }
end

also for your first log output you need to use

logError("Room2.LightStrip", Lightstrip_ColorTemperature.state.toString)

In case you only have Lightstrip_ColorTemperature you can also add a switch item to this in PaperUI

Thanks !!!
I thought yesterday evening that i should try to handle with strings and decimal values again. And then i read your solution.
Now it works!!