Control CCT LED Stripes: convert brightness and temperature to cold white and warm white

could a moderator please move this to Add-on Marketplace Rule Templates?
It does not let me add any tags like published or automation which are required to save a post in that forum.


With this template you can control CCT LED stripe’s connected to an actuator like Shelly RGBW2. It converts temperature and brightness into cold white (cw) and warm white (ww) values.

Rules DSL

Usage & Requirements:
_brightness and _temperature items are proxy items. They are controled by MainUI oh-slider widgets.
You need 4 Items per stripe and add all _brightness and _temperature items to a single group, e.g.:

Group     gCCT_LED            "All CCT LEDs"
Dimmer    LED1_brightness     "Brightness LED1"             (gCCT_LED)
Dimmer    LED1_temperature    "Temperature LED1"            (gCCT_LED)
Dimmer    LED1_cw             "cold white Channel"          //do NOT add to group!
Dimmer    LED1_ww             "warm white Channel"          //do NOT add to group!
Dimmer    LED2_brightness     "Brightness LED2"             (gCCT_LED)
Dimmer    LED2_temperature    "Temperature LED2"            (gCCT_LED)
Dimmer    LED2_cw             "cold white Channel"          //do NOT add to group!
Dimmer    LED2_ww             "warm white Channel"          //do NOT add to group!

Items _cw and _ww are items linked to your actuator’s channels. Do not add them to your UI widget. Please make sure that all items follow the same syntax like in this example or change the rule’s variables in the top.


A simple widget that controls brightness and temperature and the rule converts their values to correct ww and cw values.


Version 0.1

  • initial release


import org.openhab.core.model.script.ScriptServiceUtil
val String filename = "CCT_LED.rules"
val String strSuffixSeparator = "_"                     //Separator: 1 unique separator
val String strSuffixBrightness = "brightness"           //Suffix: at your choice
val String strSuffixTemperature = "temperature"         //Suffix: at your choice

rule "CCT_LED"
    Member of gCCT_LED changed
    logInfo(filename, "Item '{}' received command {}",,triggeringItem.state)
    var Number iNewCwState     //New value for cold white channel
    var Number iNewWwState     //New value for warm white channel
    val String strThing =     //Get Name of "Thing", i.e. LED1 or LED2 or...
    val String strType =      //Get Type (brightness oder temperature)

    if ((strType == strSuffixBrightness) && (triggeringItem.state as Number) == 0) {        //no math required. just switch off
        iNewCwState = 0
        iNewWwState = 0
    else {
        var iBrightness = ScriptServiceUtil.getItemRegistry.getItem(strThing+strSuffixSeparator+strSuffixBrightness).state as Number
			if (iBrightness == NULL) {iBrightness = (ScriptServiceUtil.getItemRegistry.getItem(strThing+"_cw").state as Number) + (ScriptServiceUtil.getItemRegistry.getItem(strThing+"_ww").state as Number)}
		var iColor = ScriptServiceUtil.getItemRegistry.getItem(strThing+strSuffixSeparator+strSuffixTemperature).state as Number
        logInfo(filename, "Setting 'Brightness' to {} and 'White Color' to {}",iBrightness,iColor)
        iNewWwState = Math::round ((iColor / 100 * iBrightness).intValue)
        iNewCwState = iBrightness - iNewWwState
    logInfo(filename, "Changing channel 'Cold White' to {} and 'Warm White' to {}",iNewCwState,iNewWwState)
1 Like