working on rules for a 5-channel LEDstrip controller I found on Eryk.io’s website, which i gratefully use. Unfortunately I couldn’t find out how he managed to drive it using OpenHAB from his webpage and google, but I’ve managed to get the it working in Openhab with the HTTP binding and the following files. For the most part at least.
I’ve managed to fix the light temperature balance using smart home designer (which actually is a great help designing the rules!). Just started work on the brightness slider for the overall brightness that would give me individual control over the white light (K) and the RGB, but allow me to dim the light proportionally.
So, the only part so far not working is the brightness slider. The problem I have is that my warm white goes to maximum brightness when I set the brightness to 0. When I use only cold-white, there is no problem.
It would be somewhere in the math, which is not my strong suit. If you spot the error, please let me know
rule "Brightness_RGBWW"
when
Item esp8266_5_br changed or
Item esp8266_5_temp changed or
Item esp8266_5_rgb changed
then
var hsbValue = HSBesp8266_5_rgb.state as HSBType
logInfo("esp8266_5 ", "hsbValue: " + hsbValue)
var inputTemperature = esp8266_5_temp.state as DecimalType
logInfo("esp8266_5 ", "inputTemperature: " + inputTemperature)
var inputBrightness = esp8266_5_br.state as DecimalType
var br = Math::round(inputBrightness.floatValue)
logInfo("esp8266_5_br", "Brightness rounded: "+ br)
// RGB TO HEX
var String rHEX = String.format("%02X", ((((hsbValue.red.intValue * 255) / 100) * br) / 100));
var String gHEX = String.format("%02X", ((((hsbValue.red.intValue * 255) / 100) * br) / 100));
var String bHEX = String.format("%02X", ((((hsbValue.red.intValue * 255) / 100) * br) / 100));
//concatenate strings to hexadecimal code
var String color = rHEX + gHEX + bHEX
//log value of inputTemperature to info log
logInfo("esp8266_5_br", "br: "+ br)
logInfo("esp8266_5_br", "hsbValue: "+ hsbValue)
// print inputTemperature
logInfo("esp8266_5 ", " esp8266_5_temp " + esp8266_5_temp)
logInfo("esp8266_5 ", "input: " + inputTemperature)
//Turn inputTemperature into a hex string for the cold-white LED
var String cwHEX = String.format("%02X", (Math::round((max-((inputTemperature/q) * br) *2.55).floatValue())))
logInfo("esp8266_5 ", " cwHEX: " + cwHEX)
// Turn inputTemperature into a hex string for the warm-white LED
var wwFLOAT = (((inputTemperature / q) * br * 2.55).floatValue())
logInfo("esp8266_5 ", " wwFLOAT: " + wwFLOAT)
var wwINT = Math::round(wwFLOAT)
logInfo("esp8266_5 ", " wwINT: " + wwINT)
val String wwHEX = String.format("%02X",wwINT)
logInfo("esp8266_5 ", " wwHEX: " + wwHEX)
// concatenate strings to hexadecimal code
val String temperature = wwHEX + cwHEX + "00"
//print variables
logInfo("esp8266_5_rgb","Color: "+ color)
logInfo("esp8266_5_temp","Temperature: "+ temperature)
logInfo("esp8266_5_br", "Brightness: "+ br)
//send commands
sendCommand( RGBesp8266_5_rgb, color )
sendCommand( esp8266_5_wb, temperature )
end
sitemap:
sitemap RGBWW label="RGBWW" {
Frame label="RGB" {
Colorpicker item=HSBesp8266_5_rgb icon="colorlight"
Slider item=esp8266_5_temp label="Temperature [%s]"
Slider item=esp8266_5_br label="Brightness"
}
}
items:
Group gRGBWW
// WiFi RGB 2
Group esp8266_5 "esp8266_5" (gRGBWW)
Color HSBesp8266_5_rgb "esp8266_5_rgb" (esp8266_5)
String RGBesp8266_5_rgb "esp8266_5_rgb" (esp8266_5) { http=">[*:GET:http://10.0.1.5/rgb/%2$s/]"}
Dimmer esp8266_5_temp "esp8266_5_wb" (gRGBWW)
String esp8266_5_wb "esp8266_5_wb" (esp8266_5) { http=">[*:GET:http://10.0.1.5/ww/%2$s/]"}
Dimmer esp8266_5_br "esp8266_5_br" (esp8266_5)
helpful suggestions always appreciated!