![]() |
|
RGB to separate objects - Printable Version +- LogicMachine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: RGB to separate objects (/showthread.php?tid=4499) |
RGB to separate objects - tomnord - 14.01.2023 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. RE: RGB to separate objects - tigi - 14.01.2023 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)) |