Valid color set but invalid value?

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
lxh7
Posts: 3
Joined: Monday 14 December 2020 18:34
Target OS: Linux
Domoticz version:
Contact:

Valid color set but invalid value?

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Valid color set but invalid value?

Post 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())
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest