16.05.2018, 09:56
OK bit of calculation is needed. Here is script which converts 3B RGB in to RGBW and saturation. You could convert it to your needs.
BR
Code:
addressred = '1/1/16'
addressgreen = '1/1/17'
addressblue = '1/1/18'
addresswhite = '1/1/19'
addresssaturation = '1/1/20'
-- Get Value of RGB picker
value = event.getvalue()
-- Convert to HEX for splitting to 3 byte values
value = lmcore.inttohex(value, 3) -- 3 = number of bytes inside value
-- Split First 2 byte HEX values from 3 byte HEX
redandgreen = string.sub(value, 1, 4)
-- Split First Value from 2 byte HEX
red = string.sub(redandgreen, 1, 2)
-- Split Last value from 2 byte HEX
green = string.sub(redandgreen, -2)
-- Split Last byte value from 3 byte HEX
blue = string.sub(value, -2)
-- Convert HEX values back to integer
valuered = lmcore.hextoint (red)
valuegreen = lmcore.hextoint (green)
valueblue = lmcore.hextoint (blue)
-- Calculate lowest value of RGB value
low = math.min(unpack({valuered, valuegreen, valueblue}))
-- Calculate highest value of RGB value
high = math.max(unpack({valuered, valuegreen, valueblue}))
-- Calculate Saturation (The saturation is the colorfulness of a color relative to its own brightness) The difference between the last two variables divided by the highest is the saturation.
saturation = math.floor((100 * ((high - low) / high)) + 0.5)
if valuered == 0 and valuegreen == 0 and valueblue == 0 then
white = 0
else
white = math.floor(((255 - saturation) / 255 * (valuered + valuegreen + valueblue) / 3)+ 0.5)
end
-- Write integer RGB values and Calculated White & Saturation to KNX
grp.update(addressred, math.floor((valuered / 2.55) + 0.5))
grp.update(addressgreen, math.floor((valuegreen / 2.55) + 0.5))
grp.update(addressblue, math.floor((valueblue / 2.55) + 0.5))
grp.update(addresswhite, math.floor((white / 2.55) + 0.5))
grp.update(addresssaturation, saturation)
------------------------------
Ctrl+F5
Ctrl+F5