Page 1 of 1

Virtual RGB switch

Posted: Saturday 17 June 2017 10:51
by lukbe
Hello everybody,
I have in domoticz virtual RGB switch and I don't know how I can read color value from color picker in LUA.

Can you help me ?

Thank you...

Re: Virtual RGB switch

Posted: Saturday 09 September 2017 8:33
by miroslavpetrov
Same question here. I have smart rgb bulbs that can be controlled with http requests. My idea is to create a dummy rgb switch which values would be used in a script which will translate the values to http requests send to the bulb.

Re: Virtual RGB switch

Posted: Saturday 09 September 2017 9:40
by morilm
I'm working on the same.

/json.htm?type=command&param=setcolbrightnessvalue&idx=xx&hue=274&brightness=40&iswhite=false
/json.htm?type=command&param=setcolbrightnessvalue&idx=xx&hue=128&brightness=42&iswhite=false&sat=2
/json.htm?type=command&param=setcolbrightnessvalue&idx=xx&hex=RRGGBB

seems to be available and working to set the values to the switch, so maybe we can decode the json response from the switch status to get the values from the switch into LUA after choosing the color on the LUA picker on the virtual RGB switch.

/json.htm?type=devices&rid=xx

(xx is the IDX number)

I can't run some test until next week... but if the Json returns the values, then it shouldn't be complicated, even not a perfect solution

regards,
Miguel

Re: Virtual RGB switch

Posted: Tuesday 15 May 2018 19:24
by morilm
Dear all

There has been changes on domoticz and now the RGB color are being posted into Json, so its possible to query


json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
local acolor = " "
ab='curl "http://192.168.1.101:8080/json.htm?type ... '..led_idx..'"'
local jsondata = assert(io.popen(ab))
local jsondevices = jsondata:read('*all')
jsondata:close()
local jsonCPM = json:decode(jsondevices)
local acolor=jsonCPM.result[1].Color

print (acolor)

---------
If you wish to decode the color reply from Json

acolorj=acolor:gsub("}",",}")
aacolor={}
for k,v in acolorj:gmatch('"(.-)":(.-),') do
aacolor[k]=v
print(k,v)
end

So you can get the RGB values in a nice table you can use later on your LUA to call phyton or PHP to set your lights

Hope it helps