This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Hue Brightness feedback
#26
Hello, I also have some problems with the feedback of the Hue lamp. 

I get the following error message. 


Quote:Resident script:22: bad argument #1 to 'decode' (string expected, got table)
stack traceback:
 [C]: in function 'decode'


I suspect the problem is the following line. 

  mylamps = json.decode(reply)

could someone take a look at my code? 
Is something wrong? 
I only have the user.hue in my user 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   ['Stehlampe Wohnzimmer'] = {state = '8/4/0', bri = '8/5/0', rgb = '8/2/0', statevalue = '', brivalue = '', colorvalue = ''}, --  ['Hue Küche'] = {state = '1/3/2', bri = '1/4/2', rgb = '1/5/2', statevalue = '', brivalue = '', colorvalue = ''}, --  ['Schalter Wohnzimmer'] = {state = '1/3/3', bri = '1/4/3', rgb = '1/5/3', statevalue = '', brivalue = '', colorvalue = ''}, --  ['Hue Schlafzimmer'] = {state = '1/3/4', bri = '1/4/4', rgb = '1/5/4', 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       log(item.state.reachable)       -- 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
Reply


Messages In This Thread
Hue Brightness feedback - by Arjen Straver - 05.07.2017, 19:30
RE: Hue Brightness feedback - by Hippolyte - 19.07.2017, 15:14
RE: Hue Brightness feedback - by Hippolyte - 27.07.2017, 07:03
RE: Hue Brightness feedback - by Albertor - 21.11.2017, 18:22
RE: Hue Brightness feedback - by Albertor - 22.11.2017, 19:51
RE: Hue Brightness feedback - by DarthPaul - 13.08.2018, 12:19
RE: Hue Brightness feedback - by DarthPaul - 14.08.2018, 04:42
RE: Hue Brightness feedback - by admin - 13.08.2018, 12:40
RE: Hue Brightness feedback - by ralwet - 19.10.2018, 20:28
RE: Hue Brightness feedback - by FatMax - 30.11.2018, 16:36
RE: Hue Brightness feedback - by admin - 30.11.2018, 16:48
RE: Hue Brightness feedback - by FatMax - 01.12.2018, 02:58
RE: Hue Brightness feedback - by admin - 03.12.2018, 07:49
RE: Hue Brightness feedback - by FatMax - 03.12.2018, 07:59
RE: Hue Brightness feedback - by timchan054 - 02.01.2019, 01:13
RE: Hue Brightness feedback - by Daniel - 02.01.2019, 13:05
RE: Hue Brightness feedback - by lenze90 - 24.02.2019, 10:07
RE: Hue Brightness feedback - by Daniel - 25.02.2019, 09:13
RE: Hue Brightness feedback - by Zandkever - 21.08.2019, 09:02
RE: Hue Brightness feedback - by admin - 21.08.2019, 09:22
RE: Hue Brightness feedback - by Zandkever - 21.08.2019, 10:20
RE: Hue Brightness feedback - by Tee_Trinker - 08.05.2020, 22:31
RE: Hue Brightness feedback - by Tee_Trinker - 13.05.2020, 19:47
RE: Hue Brightness feedback - by Firechief - 08.06.2020, 16:16
RE: Hue Brightness feedback - by Firechief - 09.06.2020, 08:24
RE: Hue Brightness feedback - by Ravi Kiran S - 25.03.2021, 10:51
RE: Hue Brightness feedback - by MLa - 30.07.2020, 20:03
RE: Hue Brightness feedback - by MLa - 31.07.2020, 18:05
RE: Hue Brightness feedback - by Sral1987 - 02.08.2020, 17:25
RE: Hue Brightness feedback - by Sral1987 - 09.08.2020, 08:27
RE: Hue Brightness feedback - by Sral1987 - 05.09.2020, 15:48
RE: Hue Brightness feedback - by Sral1987 - 05.09.2020, 16:03
RE: Hue Brightness feedback - by Sral1987 - 01.05.2023, 08:44
RE: Hue Brightness feedback - by Firechief - 08.11.2020, 12:35
RE: Hue Brightness feedback - by admin - 09.11.2020, 08:23
RE: Hue Brightness feedback - by Firechief - 09.11.2020, 15:17
RE: Hue Brightness feedback - by admin - 09.11.2020, 15:45
RE: Hue Brightness feedback - by Firechief - 09.11.2020, 16:24
RE: Hue Brightness feedback - by admin - 09.11.2020, 17:13
RE: Hue Brightness feedback - by Firechief - 09.11.2020, 17:31
RE: Hue Brightness feedback - by admin - 09.11.2020, 17:45
RE: Hue Brightness feedback - by Firechief - 09.11.2020, 18:15
RE: Hue Brightness feedback - by Sral1987 - 27.11.2020, 17:36
RE: Hue Brightness feedback - by admin - 30.11.2020, 07:26
RE: Hue Brightness feedback - by Sral1987 - 30.11.2020, 15:59
RE: Hue Brightness feedback - by Sral1987 - 01.12.2020, 15:21
RE: Hue Brightness feedback - by Karaffe - 21.01.2022, 07:50
RE: Hue Brightness feedback - by Firechief - 25.03.2023, 14:56
RE: Hue Brightness feedback - by admin - 27.03.2023, 05:28
RE: Hue Brightness feedback - by Firechief - 28.03.2023, 07:47
RE: Hue Brightness feedback - by admin - 28.03.2023, 07:58
RE: Hue Brightness feedback - by Firechief - 28.03.2023, 09:31
RE: Hue Brightness feedback - by admin - 28.03.2023, 09:31
RE: Hue Brightness feedback - by Firechief - 28.03.2023, 09:35
RE: Hue Brightness feedback - by admin - 28.03.2023, 09:39
RE: Hue Brightness feedback - by Firechief - 28.03.2023, 09:41
RE: Hue Brightness feedback - by NKereshki - 20.04.2023, 11:32
RE: Hue Brightness feedback - by NKereshki - 20.04.2023, 13:38
RE: Hue Brightness feedback - by NKereshki - 24.04.2023, 06:33
RE: Hue Brightness feedback - by NKereshki - 23.07.2025, 11:31
RE: Hue Brightness feedback - by admin - 23.07.2025, 13:06
RE: Hue Brightness feedback - by NKereshki - 23.07.2025, 13:27
RE: Hue Brightness feedback - by admin - 23.07.2025, 13:38
RE: Hue Brightness feedback - by NKereshki - 23.07.2025, 13:42
RE: Hue Brightness feedback - by admin - 23.07.2025, 13:45
RE: Hue Brightness feedback - by NKereshki - 23.07.2025, 14:16
RE: Hue Brightness feedback - by Daniel - 23.07.2025, 14:25
RE: Hue Brightness feedback - by NKereshki - 24.07.2025, 08:26
RE: Hue Brightness feedback - by admin - 24.07.2025, 08:39
RE: Hue Brightness feedback - by NKereshki - 24.07.2025, 09:14
RE: Hue Brightness feedback - by admin - 24.07.2025, 09:22
RE: Hue Brightness feedback - by NKereshki - 24.07.2025, 12:40
RE: Hue Brightness feedback - by admin - 24.07.2025, 12:54
RE: Hue Brightness feedback - by NKereshki - 24.07.2025, 14:29
RE: Hue Brightness feedback - by Sral1987 - 28.07.2025, 05:45
RE: Hue Brightness feedback - by NKereshki - 28.07.2025, 11:18
RE: Hue Brightness feedback - by admin - 25.07.2025, 07:06
RE: Hue Brightness feedback - by NKereshki - 30.07.2025, 19:27
RE: Hue Brightness feedback - by stianj - 31.07.2025, 09:40
RE: Hue Brightness feedback - by Daniel - 31.07.2025, 07:37
RE: Hue Brightness feedback - by Sral1987 - 01.08.2025, 04:53

Forum Jump: