samuel 25 Share Posted December 7, 2016 (edited) How do I put a GET status from Hue lamp into variable to store? HueGtw = Net.FHttp("IP-address",portNumber) HueGtw:GET('/api/xxxxxx/lights/3) Help would be appreciated? Edited December 8, 2016 by samuel Where is the solution that you provide? This does not belonge to Crowd's Solutions. Please, read descriptions of forum. Quote Link to post Share on other sites
0 T.Konopka 1 Share Posted December 7, 2016 The topic has been moved from "Virtual Devices" to "Developer". Temat został przeniesiony z "Virtual Devices" do "Developer". Quote Link to post Share on other sites
0 samuel 25 Author Share Posted December 8, 2016 is there anyone to help me how to setup variable from a GET Hue status? Quote Link to post Share on other sites
0 AutoFrank 363 Share Posted December 8, 2016 17 minutes ago, samuel said: is there anyone to help me how to setup variable from a GET Hue status? Hi Could you expand a little what you are looking to do and whether it's in a scene or a virtual device ? Thanks Quote Link to post Share on other sites
0 samuel 25 Author Share Posted December 8, 2016 sure... in a VD button... i would like to make a scene which runs, when the button is been pressed 1. it saves the old setting of hue light status in a variable or different way 2. then applies the new light setting - holds it for 5min 3 return to old setting saved status in variable that's it basically Quote Link to post Share on other sites
0 AutoFrank 363 Share Posted December 8, 2016 (edited) 34 minutes ago, samuel said: sure... in a VD button... i would like to make a scene which runs, when the button is been pressed 1. it saves the old setting of hue light status in a variable or different way 2. then applies the new light setting - holds it for 5min 3 return to old setting saved status in variable that's it basically This is untested and a bit rough. I've also never worked with Hue so I don't know the api methods but it should help you get started Create a VD Set the IP address of the VD to the address of the Hue Bulb or hub (I assume) Sett the Port number of the VD to the correct port (alternatively you could place these in line 10 of the code below and delete the first 4 lines) Create a button - label accordingly Leave ID as is Check 'Lua code' under text box Copy the following into the text box local device = fibaro:getSelfId(); local zonename = fibaro:getName(device); local ipaddress = fibaro:getValue(device, "IPAddress"); local port = fibaro:getValue(device, "TCPPort"); --set variable for new temporary level change local tempLevel = 80 -- read the current level Hue = Net.FHttp(ipaddress, port); response = Hue:GET("/api/xxxxxx/lights/3") -- adjust this url based on the hue api jsonTable = json.decode(response) --store the current level local currentLevel = jsonTable.level -- adjust for the structure of the response -- execute the change to the new level response = Hue:GET("/api/xxxxxx/lights/3/"..tempLevel.."") -- sleep for 5 mins (5x60x1000) fibaro:sleep(300000) -- execute the change to the previous level response = Hue:GET("/api/xxxxxx/lights/3/"..currentLevel.."") Line 11, 18 and 24 will need to be adjusted based on the api structure If you're not sure then try dropping http://IPAddress/api/xxxxx/3 into a broswer (assuming the 3 is the id of the bulb you should see the value pairs and should tell you what to replace jsonTable.level to Line 18 and 24 may also need to be adjusted I assume it was '.....................lights/id/level' Maybe somebody with hue experience can help get you the rest of the way -frank Edited December 8, 2016 by AutoFrank Quote Link to post Share on other sites
0 AutoFrank 363 Share Posted December 8, 2016 I also found this topic from Sankotronic on a VD for Hue It might also help https://forum.fibaro.com/index.php?/topic/14718-howto-philips-hue-control-light-v1-virtual-device/&page=2#comment-95697 Quote Link to post Share on other sites
0 samuel 25 Author Share Posted December 10, 2016 Eventually from your example and the example from Sankotronic i got it working thanks -- define PhilipsHUE bridge user hueUser = "xxxxxx" -- define Hue ID Number hueLightNo = 2 -- connect to the Hue bridge Hue = Net.FHttp("IP-adress",Port-Number) -- HTTP GET to get all the info from the lamp response, status, errorCode = Hue:GET('/api/'..hueUser..'/lights/'..hueLightNo); fibaro:sleep(100); -- continue if HTTP status code is 200 if (tonumber(status) == 200) then jsonTable = json.decode(response) -- check if error table exists if (jsonTable[1] ~= nil) then -- show error information errorType = jsonTable[1].error.type errorDescription = jsonTable[1].error.description fibaro:debug("Error type = "..errorType) fibaro:debug("Error description = "..errorDescription) if (errorType == 1) then fibaro:log("Hue: Unauthorized user") elseif (errorType == 3) then fibaro:log("Hue: Incorrect light ID") end else -- get the on state hueOn = jsonTable.state.on fibaro:debug("hueOn = " .. tostring(hueOn)); -- get the brightness value (0-254) hueBrightness = tonumber(jsonTable.state.bri) fibaro:debug("hueBrightness = "..hueBrightness); -- get the color value (0-65535) hueColor = tonumber(jsonTable.state.hue) fibaro:debug("hueColor = "..hueColor); -- get the saturation value (0-254) hueSaturation = tonumber(jsonTable.state.sat) fibaro:debug("hueSaturation = "..hueSaturation); -- get the reachable state hueReachable = jsonTable.state.reachable fibaro:debug("hueReachable = " .. tostring(hueReachable)); if (hueReachable == true) then Hue:PUT('/api/xxxxxxxx/lights/2/state', '{"on":true, "sat":254, "bri":254, "hue":20305}') fibaro:debug("Apply new scene: Samuel's Home"); -- wait 5 minutes fibaro:sleep(60000*5) else fibaro:log("Hue: Light not reachable"); end -- might be that i have to swap hue sat and hue color !! OLD VALUE put back!! Hue:PUT('/api/'..hueUser..'/lights/'..hueLightNo..'/state', '{"on":'..tostring(hueOn)..',"sat":'..hueSaturation..',"bri":'..hueBrightness..',"hue":'..hueColor..'}') fibaro:debug("Apply previous setting"); end end Quote Link to post Share on other sites
0 AutoFrank 363 Share Posted December 10, 2016 5 hours ago, samuel said: Eventually from your example and the example from Sankotronic i got it working thanks -- define PhilipsHUE bridge user hueUser = "xxxxxx" -- define Hue ID Number hueLightNo = 2 -- connect to the Hue bridge Hue = Net.FHttp("IP-adress",Port-Number) -- HTTP GET to get all the info from the lamp response, status, errorCode = Hue:GET('/api/'..hueUser..'/lights/'..hueLightNo); fibaro:sleep(100); -- continue if HTTP status code is 200 if (tonumber(status) == 200) then jsonTable = json.decode(response) -- check if error table exists if (jsonTable[1] ~= nil) then -- show error information errorType = jsonTable[1].error.type errorDescription = jsonTable[1].error.description fibaro:debug("Error type = "..errorType) fibaro:debug("Error description = "..errorDescription) if (errorType == 1) then fibaro:log("Hue: Unauthorized user") elseif (errorType == 3) then fibaro:log("Hue: Incorrect light ID") end else -- get the on state hueOn = jsonTable.state.on fibaro:debug("hueOn = " .. tostring(hueOn)); -- get the brightness value (0-254) hueBrightness = tonumber(jsonTable.state.bri) fibaro:debug("hueBrightness = "..hueBrightness); -- get the color value (0-65535) hueColor = tonumber(jsonTable.state.hue) fibaro:debug("hueColor = "..hueColor); -- get the saturation value (0-254) hueSaturation = tonumber(jsonTable.state.sat) fibaro:debug("hueSaturation = "..hueSaturation); -- get the reachable state hueReachable = jsonTable.state.reachable fibaro:debug("hueReachable = " .. tostring(hueReachable)); if (hueReachable == true) then Hue:PUT('/api/xxxxxxxx/lights/2/state', '{"on":true, "sat":254, "bri":254, "hue":20305}') fibaro:debug("Apply new scene: Samuel's Home"); -- wait 5 minutes fibaro:sleep(60000*5) else fibaro:log("Hue: Light not reachable"); end -- might be that i have to swap hue sat and hue color !! OLD VALUE put back!! Hue:PUT('/api/'..hueUser..'/lights/'..hueLightNo..'/state', '{"on":'..tostring(hueOn)..',"sat":'..hueSaturation..',"bri":'..hueBrightness..',"hue":'..hueColor..'}') fibaro:debug("Apply previous setting"); end end Excellent - glad you got it working Looks like a good solid solution - Do you want to post it in the 'solutions' part of the forum. I'm sure others could use it as well -frank Quote Link to post Share on other sites
0 Mateo 2 Share Posted October 5, 2019 Hello, As all newbie, love those solid codes Thanks for this great solution I would like to do almost the same but i'm blocked and need some of your help... For visual alarm in my house (all lamps red, all lamps blue, all lamps blincking...) when events (intrusion, flood, door bell...), i would like to: * Store all current hue settings * send a visual alert to all lamp * come back to previous settings after x seconds. Most of the idea is here but for one lamp. I do have circa 50. I've already extracted from hue bridge all lamps settings and i'm trying to store it in a globalVariable to then leverage it from other VD or scenes but i'm blocked. Whether i do not well store, whether i don't know how scripting how getting and storing data in return ... but need your help thanks in advance, br Quote Link to post Share on other sites
Question
samuel 25
How do I put a GET status from Hue lamp into variable to store?
HueGtw = Net.FHttp("IP-address",portNumber)
HueGtw:GET('/api/xxxxxx/lights/3)
Help would be appreciated?
Where is the solution that you provide? This does not belonge to Crowd's Solutions. Please, read descriptions of forum.
Link to post
Share on other sites
9 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.