Hi, I asked your question to the chatgpt AI and got a working result, hope this works for you too.
Function to convert KNX RGB datatype to separate 1-byte values:
Code:
function knxRGBToBytes(knxRGB)
local red = bit.rshift(bit.band(knxRGB, 0xFF0000), 16)
local green = bit.rshift(bit.band(knxRGB, 0x00FF00), 8)
local blue = bit.band(knxRGB, 0x0000FF)
return red, green, blue
end
-- Example usage
local knxRGB = grp.getvalue('x/x/x')
local red, green, blue = knxRGBToBytes(knxRGB)
log(red, green, blue)
The other function convert separate 1-byte values to KNX RGB datatype:
Code:
function bytesToKNXRGB(red, green, blue)
local knxRGB = bit.lshift(red, 16) + bit.lshift(green, 8) + blue
return knxRGB
end
-- Example usage
local red, green, blue = 255, 102, 51
local knxRGB = bytesToKNXRGB(red, green, blue)
log(string.format("%X", knxRGB))