This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

RGB to separate objects
#1
Hi. I know I've seen it on the forum before, but could not find it.

To get RGB to work in Google Home, I need to convert RGB (232.600) to separate 1byte values. And also convert the status back from 1byte to 232.600.
Reply
#2
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))
Reply


Forum Jump: