Jump to content
  • 0

How to put a GET status from HUE in a variable?


Question

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 by samuel
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

  • 0
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

Link to post
Share on other sites
  • 0

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

 

Link to post
Share on other sites
  • 0
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 by AutoFrank
Link to post
Share on other sites
  • 0

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 

Link to post
Share on other sites
  • 0
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

 

 

Link to post
Share on other sites
  • 0

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

 

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...