Page 1 of 1

Valid color set but invalid value?

Posted: Monday 14 December 2020 18:43
by lxh7
I have a problem getting the color temperature value from a Warm White / Cool White dimable light (RGBWW device?). My code is roughly this:

Code: Select all

local d = domoticz.devices('Light 1')
domoticz.log(d.name)
local colorSet = d.color
domoticz.log(colorSet)
local t = colorSet.t
domoticz.log(t)
In the log I get this:

Code: Select all

2020-12-14 18:11:49.589 Status: dzVents: Info: Switch 1: Light 1
2020-12-14 18:11:49.589 Status: dzVents: Info: Switch 1: {"b":0,"cw":102,"g":0,"m":2,"r":0,"t":153,"ww":153}
2020-12-14 18:11:49.589 Status: dzVents: Info: Switch 1: nil 
If I use colorSet['t'] I also get nil.

I'm new to Lua and dzVents... Is this Lua playing rough? Or how to get a value from a (seemingly) correct color set?

Thanks for any light you can shed

Re: Valid color set but invalid value?

Posted: Monday 14 December 2020 21:31
by waaren
lxh7 wrote: Monday 14 December 2020 18:43 If I use colorSet['t'] I also get nil.
the color attribute is a JSON string. You first have to make it a Lua table before you can address the table attributes individually.

-- the hard way

Code: Select all

local d = domoticz.devices('Light 1')
domoticz.log('Device name is ' ..  d.name)
local colorJSONString = d.color
domoticz.log('Color JSON string is ' .. colorJSONString)
local colorTable = domoticz.utils.fromJSON(colorJSONString)
domoticz.log('Color temperature is ' .. colorTable.t)
domoticz.utils.dumpTable(colorTable)
-- the easy way

Code: Select all

local d = domoticz.devices('Light 1')
domoticz.log('Device name is ' ..  d.name)
domoticz.log('Color temperature  is ' ..  d.getColor().t)
domoticz.utils.dumpTable(d.getColor())