Dear Admin,
I've added these lines to the resident Hue script. Now none of the Hue lamp statusses are updated, neither the brightness nor the rgb. These worked before i added the lines. I do not get log's when switching lamps on or off. No error logs as well. I'm using the v5 user.hue library.
Kind regards
Can it be that there's a typo in the lines?
I've added these lines to the resident Hue script. Now none of the Hue lamp statusses are updated, neither the brightness nor the rgb. These worked before i added the lines. I do not get log's when switching lamps on or off. No error logs as well. I'm using the v5 user.hue library.
Code:
-- Set name (Lookup in HUE app under light configuration) and feedback adresses (don't change statevalue, brivalue and colorvalue as they are used as memoryfield)
addressmapping = {
-- Name -- On/Off FB -- Bright FB -- Color FB
['Led terras'] = {state = '20/0/1', bri = '20/1/1', rgb = '20/2/1', ct = '20/3/1', statevalue = '', brivalue = '', colorvalue = ''},
['Keuken Eiland'] = {state = '20/0/2', bri = '20/1/2', rgb = '20/2/2', statevalue = '', brivalue = '', colorvalue = ''},
['Keuken Werkblad R'] = {state = '20/0/3', bri = '20/1/3', rgb = '20/2/3', statevalue = '', brivalue = '', colorvalue = ''},
['Keuken Werkblad L'] = {state = '20/0/4', bri = '20/1/4', rgb = '20/2/4', statevalue = '', brivalue = '', colorvalue = ''},
['Douche L'] = {state = '20/0/5', bri = '20/1/5', rgb = '20/2/5', statevalue = '', brivalue = '', colorvalue = ''},
['Douche R'] = {state = '20/0/6', bri = '20/1/6', rgb = '20/2/6', statevalue = '', brivalue = '', colorvalue = ''},
['Keuken Werkblad'] = {state = '20/0/7', bri = '20/1/7', rgb = '20/2/7', statevalue = '', brivalue = '', colorvalue = ''},
}
-- Set polling interval in seconds
interval = 1
-- Use logging
logging = true
require('user.hue')
require('json')
-- loop indefenitly
while true do
reply = getHueLights()
mylamps = json.decode(reply)
-- get groups start
reply = getHueGroups()
groups = json.pdecode(reply)
if type(groups) == 'table' then
for k, v in pairs(groups) do
mylamps[ k ] = v
end
end
-- get groups end
for _, item in pairs(mylamps) do
-- Check if lamp is found by bridge otherwise it make no sense to send commands
if item.state.reachable == true then
-- On/Off
name = addressmapping[item.name]
if name then
addr = addressmapping[item.name]['state']
if addr and addr ~= '' then
currentvalue = addressmapping[item.name]['statevalue']
if currentvalue ~= item.state.on then
grp.update(addr, item.state.on)
addressmapping[item.name]['statevalue'] = item.state.on
if logging == true then
log('lamp ' .. item.name .. ' state is: ' .. tostring(item.state.on))
end
end
end
end
-- Brightness
name = addressmapping[item.name]
if name then
addr = addressmapping[item.name]['bri']
if addr and addr ~= '' then
-- Check if lamp is on otherwise overrule BRI value to 0
if item.state.on == false then
item.state.bri = 0
end
currentvalue = addressmapping[item.name]['brivalue']
if currentvalue ~= item.state.bri then
grp.update(addr, math.floor((tonumber(item.state.bri)/2.55) + 0.5))
addressmapping[item.name]['brivalue'] = item.state.bri
if logging == true then
log('lamp ' .. item.name .. ' brightness is: ' .. math.floor((tonumber(item.state.bri)/2.55) + 0.5) .. ' %')
end
end
end
end
-- Color
name = addressmapping[item.name]
if name then
addr = addressmapping[item.name]['rgb']
if addr and addr ~= '' then
-- Check if lamp is on otherwise overrule color value to 0
if item.state.on == false then
colorvalue = 0
end
if item.state.colormode == 'xy' then
currentvalue = addressmapping[item.name]['colorvalue']
colorvalue = xy_to_rgb(item.state.xy[1],item.state.xy[2],item.state.bri)
--colorvalue = xyz_to_rgb((item.state.xy[1] * 100), (item.state.xy[2] * 100))
if currentvalue ~= colorvalue then
grp.update(addr, colorvalue)
addressmapping[item.name]['colorvalue'] = colorvalue
if logging == true then
log('lamp ' .. item.name .. ' color is: ' .. colorvalue)
end
end
elseif item.state.colormode == 'ct' then
currentvalue = addressmapping[item.name]['colorvalue']
--colortemp = math.floor((item.state.ct / 0.0769) + 0.5) --0.0769230769230769
colortemp = math.abs((item.state.ct - 500) / 2)
colortemp = math.floor(colortemp + 0.5)
colortemp = 80 + colortemp
if colortemp > 255 then
colortemp = 255
end
r = lmcore.inttohex(255, 1)
g = lmcore.inttohex(255, 1)
b = lmcore.inttohex(colortemp, 1)
rgb = r .. g .. b
colortemp = lmcore.hextoint(rgb,3)
if currentvalue ~= colortemp then
--colortempconverted = ct_to_rgb(colortemp)
grp.update(addr, colortemp)
addressmapping[item.name]['colorvalue'] = colortemp
if logging == true then
log('lamp ' .. item.name .. ' color is: ' .. colortemp)
end
end
end
end
end
end
--log('manufacturername = ' .. item.manufacturername)
--log('swversion = ' .. item.swversion)
--log('type = ' .. item.type)
--log('ct = ' .. item.state.ct)
--log('reachable = ' .. item.state.reachable)
--log('alert = ' .. item.state.alert)
--log('on = ' .. item.state.on)
--log('bri = ' .. item.state.bri)
--log('colormode = ' .. item.state.colormode)
--log('hue = ' .. item.state.hue)
--log('sat = ' .. item.state.sat)
--log('effect = ' .. item.state.effect)
--log('x = ' .. item.state.xy[1])
--log('y = ' .. item.state.xy[2])
--log('uniqueid = ' .. item.uniqueid)
--log('modelid = ' .. item.modelid)
--log('name = ' .. item.name)
end
-- Delay loop
os.sleep(interval)
end
Kind regards
Can it be that there's a typo in the lines?
Code:
-- get groups start
reply = getHueGroups()
groups = json.pdecode(reply) -- ==>json.decode(reply) ???
if type(groups) == 'table' then
for k, v in pairs(groups) do
mylamps[ k ] = v
end
end
-- get groups end
Novice DIY with a HL and KNX basics trying to ...