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.
Language:
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.
Screenshots
A simple widget that controls brightness and temperature and the rule converts their values to correct ww and cw values.
Changelog
Version 0.1
- initial release
Resources
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"
when
Member of gCCT_LED changed
then
logInfo(filename, "Item '{}' received command {}",triggeringItem.name,triggeringItem.state)
var Number iNewCwState //New value for cold white channel
var Number iNewWwState //New value for warm white channel
val String strThing = triggeringItem.name.toString.split(strSuffixSeparator).get(0) //Get Name of "Thing", i.e. LED1 or LED2 or...
val String strType = triggeringItem.name.toString.split(strSuffixSeparator).get(1) //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)
ScriptServiceUtil.getItemRegistry.getItem(strThing+"_cw").sendCommand(iNewCwState)
ScriptServiceUtil.getItemRegistry.getItem(strThing+"_ww").sendCommand(iNewWwState)
end