02.08.2020, 17:25
Hi Ervin,
since i update the user.hue to V4 i get this error message every time:
this is my resident script:
line 62 is the grp.write, before i used your script in V3.
HW is an HL V1 running LM Firmware 202007 RC2.
BR
Lars
since i update the user.hue to V4 i get this error message every time:
Code:
Resident script:62: attempt to perform arithmetic on a nil value
stack traceback:
this is my resident script:
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
['Schlafzimmer'] = {state = '10/1/27', bri = '10/1/15', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Laura Wand Links'] = {state = '32/1/7', bri = '32/1/9', rgb = '32/1/16', statevalue = '', brivalue = '', colorvalue = ''},
['Laura Wand Rechts'] = {state = '32/1/8', bri = '32/1/10', rgb = '', statevalue = '', brivalue = '', colorvalue = ''},
['Küche Led'] = {state = '32/1/11', bri = '32/1/13', rgb = '10/1/5', statevalue = '', brivalue = '', colorvalue = ''},
['Küche indirekt'] = {state = '32/1/12', bri = '10/1/3', rgb = '32/1/14', statevalue = '', brivalue = '', colorvalue = ''},
['Esstisch'] = {state = '10/1/157', bri = '10/1/159', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Laura Zelt'] = {state = '10/1/25', bri = 'x/x/x', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Wohnzimmer Links'] = {state = '32/1/3', bri = '32/1/5', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Wohnzimmer Rechts'] = {state = '32/1/4', bri = '32/1/6', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Kinderzimmer Links'] = {state = '32/1/17', bri = '32/1/19', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Kinderzimmer Rechts'] = {state = '32/1/18', bri = '32/1/20', rgb = 'x/x/x', statevalue = '', brivalue = '', colorvalue = ''},
['Küche Theke'] = {state = '10/1/161', bri = '10/1/163', rgb = 'x/x/x', 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)
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.write(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.write(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.write(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.write(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
line 62 is the grp.write, before i used your script in V3.
HW is an HL V1 running LM Firmware 202007 RC2.
BR
Lars