I a trying to create a rule that blinks a hue bulb (with the alert channel), but saves the current bulb state upfront and restores that state afterwards. For example: the light is in colortemperature mode (a warm white) and when I press a UI button, the bulb blinks red 15 times and then switches back to it’s previous state. When restoring, I should set the color OR the coltemp channel and NOT both.
The API has a colormode = “ct” value, but this does not seem to be available as a channel.
Is there a (another) way to get the state of colormode?
You can try to use the HTTP binding and a JavaScript Transformation to get the colormode value via the Philips Hue API. Replace <HUE_BRIDGE_IP>, <HUE_API_KEY> and <BULB_ID> with your dependant values.
I don’t know Hue, but can’t you just save off the states of the Items linked to the Hue bulb in question to a local var and then sendCommand those states back to the bulb after the lights are done blinking? Assuming that works, that would be a more generic approach that would work with any type of light, not just Hue.
I have since discovered that I can use the color code to also set the white temperature. So I’m using that for now.
This is my rule for the record.
rule "BowlBlinkRed"
when
Item Light_StudyBowl_Blink received command
then
var String BlinkColor = ""
switch(receivedCommand) {
case "RED": BlinkColor = "0,100,100"
case "BLUE": BlinkColor = "240,100,100"
default: BlinkColor = "0,0,100"
}
// save current settings
val SavedSwitch = Light_StudyBowl.state // ON or OFF
val SavedColor = Light_StudyBowl_Color.state // HSB
// set color to red and long blink
Light_StudyBowl_Color.sendCommand( BlinkColor )
Light_StudyBowl_Alert.sendCommand("LSELECT")
Thread::sleep(15 * 1000) // let alert finish
// restore
if (SavedSwitch == OFF) {
Light_StudyBowl.sendCommand("OFF")
} else {
Light_StudyBowl_Color.sendCommand( '' + SavedColor )
}
end
Thanks for sharing your rule. I have this on my to-do list for a while. This will be a good point to start with and to adapt it for my requirements.
You said that you use an item linked to the color channel, right? I always thought I have to send HSBType values as commands. I am happy to see, that StringType works too.
Thank you for sharing your rule.
I tried it out but have a problem with the lights not restoring their color values. If they are off and I send the blink command, they retain the Blink color values. If they were on when the command was sent, everything works fine and the values are restored.
Any pointers on where to look? Is there a debugger where you can see the values of the variables when running a rule?
Argh! It’s been a while since I’ve actually looked at the code.
A suggestion would be to modify the restore part of the rule to also restore the saved color when the light was off before blinking (untested, YMMV):
Thank you, will try that out (as soon as I get back from summer holidays, that is…)
I am trying to blink a Hue LED stripe when a window is open and I leave the house…