I tried to enhance my rule, which handels hue white light quite perfect, to color lights. It’s seems not be as easy as expected, because I cant access the brightness directly because the color lights use the HSBType.
With the following code I get the current parameters of the bulb.
var Hue, Brightness, Saturation ;
var things = Java.type('org.openhab.core.model.script.actions.Things');
var currentState = Java.type('org.openhab.core.library.types.HSBType');
...
currentState = itemRegistry.getItem('Huecolorlamp2TestLeuchte_Farbe').getState();
Hue = currentState.getHue();
Brightness = currentState.getBrightness();
Saturation = currentState.getSaturation();
So far so good. Then I modify one parameter, e.g. the brightness, to send the new parameter set back to the lamp …
But this won’t work. I tried to find some simple example … but I didn’t found one. It seams that the toString methode is not called correct, but … I have to less JavaScript experiences. Do I have to include a further library … don’t know
Can someone give me the right hint to solve this? Just a piece of code that addresses the same problem.
In JS when you call a function you must call it as a function. There is no toString, it’s toString().
But if you just want to change the brightness, you can sendCommand(newBrightness) to a Color Item and it will only adjust the brightness. To turn it on or off you can sendCommand(“ON”).
Okay that was as easy as expected … but … if I want to change the color, what have I to then? Is there an other simple command to change the color or is it then necessary to use the HSBType?
For the record only, I changed the toString as I understood this to