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.

Philips Hue api v2
#1
Has anyone already made any code for the Philips Hue api V2?

Why the v2 api? because i want to trigger dynamic scenes and thats not possible in the v1 api.

Please correct my code is you see improvements.

Code:
--[[
https://developers.meethue.com/develop/hue-api-v2/api-reference/
https://developers.meethue.com/develop/hue-api-v2/getting-started/
--]]

-- Load modules
https = require('ssl.https')
ltn12 = require('ltn12')
json = require('json')

local bridge = 'ip of the bridge'
local usr = 'same user as api v1'

-- bridge communication base
function hueExec(iMethod, iCommand, iBody)
  resp = {}
  body = json.encode(iBody)
  res, code, headers = https.request({
    url = 'https://'..bridge..'/clip/v2/resource'..iCommand,
    method = iMethod,
    source = ltn12.source.string(body),
    sink = ltn12.sink.table(resp),
    headers = { ['hue-application-key'] = usr,
                ['Content-Type'] = 'application/json',
                ['Accept'] = 'application/json',
                ['Content-Length'] = #body   
              }
  })
  -- handle feedback
  if not res or code ~= 200 then
    return
  else
    resp = table.concat(resp)
    resp = json.pdecode(resp)
    return resp
  end
end


-- get all lights
function getLights()
    return hueExec('GET', '/light')
end
--log(getLights())


-- get light
function getLight(iLight)
    return hueExec('GET', '/light/'..iLight)
end
--log(getLight('e4a834c9-9ca3-4f2d-98be-669c55a90b5d'))


-- activate scene (active or dynamic_palette)
function runScene(iScene, iAction)
  vAction = iAction or 'active'
    hueExec('PUT', '/scene/'..iScene, {recall = {action = vAction}})
end
--runScene('185d4226-213e-4f01-913b-91c22d85bfac') -- living soho scene
--runScene('185d4226-213e-4f01-913b-91c22d85bfac', 'dynamic_palette') -- living soho dynamic
Reply


Messages In This Thread
Philips Hue api v2 - by gjniewenhuijse - 02.02.2022, 13:17
RE: Philips Hue api v2 - by gjniewenhuijse - 02.02.2022, 14:53
RE: Philips Hue api v2 - by admin - 02.02.2022, 15:53
RE: Philips Hue api v2 - by gjniewenhuijse - 02.02.2022, 18:51
RE: Philips Hue api v2 - by admin - 03.02.2022, 07:21
RE: Philips Hue api v2 - by gjniewenhuijse - 03.02.2022, 09:11
RE: Philips Hue api v2 - by admin - 03.02.2022, 09:22
RE: Philips Hue api v2 - by gjniewenhuijse - 03.02.2022, 09:34
RE: Philips Hue api v2 - by admin - 03.02.2022, 09:50
RE: Philips Hue api v2 - by gjniewenhuijse - 03.02.2022, 10:12
RE: Philips Hue api v2 - by gjniewenhuijse - 03.02.2022, 14:58
RE: Philips Hue api v2 - by Joep - 10.01.2023, 09:16

Forum Jump: