Page 1 of 1
How to set device RGBWW via Lua script?
Posted: Thursday 20 September 2018 21:28
by ben53252642
Hey folks,
Does anyone know how to set a RGBWW Domoticz virtual device via Lua script?
Eg: commandArray['LED'] = 'On' & Colortemp= 180 & Brightness = 80
or
Eg: commandArray['LED'] = 'On' & R=180 B=80 G=221 & Brightness = 80
Thanks
Re: How to set device RGBWW via Lua script?
Posted: Thursday 20 September 2018 22:53
by Nautilus
You can use these examples as a reference:
https://www.domoticz.com/wiki/Domoticz_ ... emperature
Also, a nice way to see the exact API call is to open developer console in a browser (e.g. in Chrome you can do it by right-click -> inspect), select network tab and then perform the action you want to script in the GUI.
Re: How to set device RGBWW via Lua script?
Posted: Thursday 20 September 2018 23:09
by waaren
ben53252642 wrote: ↑Thursday 20 September 2018 21:28
Does anyone know how to set a RGBWW Domoticz virtual device via Lua script?
I don't think it can be done with a "native" commandArray command yet.
In the domoticz database the field Color in table deviceStatus for RGBWW devices is like {"b":129,"cw":0,"g":211,"m":3,"r":254,"t":0,"ww":0}
If I peek in the dzVents device-adapter for RGBWW devices, the setRGB command is coded as a JSON call like
Code: Select all
url = domoticz.settings['Domoticz url'] ..
'/json.htm?param=setcolbrightnessvalue&type=command&idx=' .. device.id ..
'&hue=' .. tostring(h) ..
'&brightness=' .. tostring(b) ..
'&iswhite=' .. tostring(isWhite)
where hue, brightness and isWhite are the result of a quite complicated conversion function from rgb
- Spoiler: show
Code: Select all
function self.rgbToHSB(r, g, b)
local hsb = {h = 0, s = 0, b = 0}
local min = math.min(r, g, b)
local max = math.max(r, g, b)
local delta = max - min;
hsb.b = max;
hsb.s = max ~= 0 and (255 * delta / max) or 0;
if (hsb.s ~= 0) then
if (r == max) then
hsb.h = (g - b) / delta
elseif (g == max) then
hsb.h = 2 + (b - r) / delta
else
hsb.h = 4 + (r - g) / delta
end
else
hsb.h = -1
end
hsb.h = hsb.h * 60
if (hsb.h < 0) then
hsb.h = hsb.h + 360
end
hsb.s = hsb.s * (100 / 255)
hsb.b = hsb.b * (100 / 255)
local isWhite = (hsb.s < 20)
return hsb.h, hsb.s, hsb.b, isWhite
end