rule "LED-Strom automatisch schalten"
when
Item rgb_wozi received update
then
if (rgb_wozi.state != "0.0,0.0,0.0") {
sendCommand(sw_ledcontroller, ON)
logDebug("light", "WZ RGB-State: " + rgb_wozi.state)
} else {
sendCommand(sw_ledcontroller, OFF)
}
end
but that does not work correctly. The If-statement always is returning as true…
I want that the power (sw_ledcotroller) is switched off when the off-button is used on the Colorpicker…
On first sight I would say that the rgb_wozi state is not of type String, but of RGBType(? or HSBType, if there is no RGBType class). At least I know that the ColorPicker item goes with HSBType…
So your if-statement can’t become true…
I’ve done something similar with Hue lights which have a HSBType state and go to the brightness (b) as a brightness of 0% means off (at least from my point of view).
when
Item rgb_ess1 received update
then
if (rgb_ess1.getStateAs(typeof(OnOffType)).equals(OFF)) {
sendCommand(sw_test, OFF)
logDebug(“light”, "WZ RGB-State: " + rgb_wozi.state)
} else {
sendCommand(sw_test, ON)
}
end
2015-11-24
08:07:19.783 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during
the execution of rule ‘LED-Strom automatisch schalten’: OnOffType
Also tried
if (rgb_ess1.getStateAs(typeof(OnOffType)) == OFF) {
if (rgb_ess1.state.getBrightness() == 0) {
if (rgb_ess1.state.b == 0) {
and every of those combinations with .equals(0)
None working…
2015-11-24
07:48:14.349 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during
the execution of rule ‘LED-Strom automatisch schalten’: Cannot cast
org.openhab.core.library.types.HSBType to void
Can you provide mme with an example how you solved it?
I was just only on my tablet which makes things mor complicated than I thought…
Here you find the part of my “Hue Scenes in OpenHab” rule:
items.keySet.forEach [ key |
var OnOffType sw
var HSBType hsb
var PercentType value = items.get(key)
if (value instanceof HSBType) {
logDebug("org.openhab.model.script.lights", "value for key " + key + " is of type HSBType")
hsb = value as HSBType
logDebug("org.openhab.model.script.lights", "hsb.getBrightness() for key " + key + ": " + hsb.getBrightness())
if(hsb.getBrightness() == PercentType::ZERO) { sw = OFF } else { sw = ON }
} else {
logDebug("org.openhab.model.script.lights", "value for key " + key + " is NOT of type HSBType")
logDebug("org.openhab.model.script.lights", "value for key " + key + ": " + value)
if(value == PercentType::ZERO) { sw = OFF } else { sw = ON }
}
logDebug("org.openhab.model.script.lights", "switch for key " + key + " :" + sw)
var String item
var String state
if (sw == OFF) {
item = "SWT_" + key
state = sw.toString
} else if (value instanceof HSBType) {
item = "CLR_" + key
state = hsb.toString
} else {
item = "DIM_" + key + "_Dimm"
state = value.toString
}
logInfo("org.openhab.model.script.lights", "execute: sendCommand(" + item + ", " + state + ")")
sendCommand(item, state)
try {
Thread::sleep(250)
} catch (InterruptedException e) {
// Ignore this
}
]
In “items” you have a Map with the name of the light as key and either the color or the brightness of the lamp depending whether it’s a RGB or white lamp. My items are named SWT_<lightname> for ON/OFF Switch, CLR_<lightname> for Colorpicker und DIM_<lightname>_DIMM for dimmer items.
It’s not exactly what you do (I’m still thinking about how to implement a similar (generic) rule to identify Hue scenes in OpenHab) but it’s the other way round so I hope this will give you an idea.
Thanks, Dieter!
You lead me to the right solution. PercentType did not work for me eighter but that does:
rule "LED-Strom automatisch schalten"
when
Item rgb_wozi received update or
Item rgb_regal received update or
Item rgb_wzschrank received update or
Item rgb_ess1 received update or
Item rgb_ess2 received update
then
if ((rgb_wozi.state as HSBType).getBrightness() == 0 && (rgb_regal.state as HSBType).getBrightness() == 0 && (rgb_wzschrank.state as HSBType).getBrightness() == 0 && (rgb_ess1.state as HSBType).getBrightness() == 0 && (rgb_ess2.state as HSBType).getBrightness() == 0) {
logDebug("light", "LED-Hauptbeleuchtung wird ausgeschaltet")
sendCommand(sw_ledcontroller, OFF)
} else {
logDebug("light", "LED-Hauptbeleuchtung wird eingeschaltet")
sendCommand(sw_ledcontroller, ON)
}
end