philips-hue.lua
local BRIDGE_IP = assert(os.getenv("HUE_IP"), "please set env var 'HUE_IP'")
local API_KEY = assert(os.getenv("HUE_KEY"), "please set env var 'HUE_KEY'")
require "logging"
local SSE_Client = require "copas-sse/client"
local Timer = require "copas.timer"
local copas = require "copas"
local client = SSE_Client.new {
url = "https://" .. BRIDGE_IP .. "/eventstream/clip/v2",
headers = { ["Hue-Application-Key"] = API_KEY },
}
local event_queue = client:start()
event_queue:add_worker(function(msg)
if msg.type then print("type :" .. msg.type) end
if msg.id then print("id :" .. msg.id) end
if msg.event then print("event:" .. msg.event) end
if msg.data then print("data :" .. msg.data) end
print("")
end)
Timer.new {
delay = 60,
callback = function() client:close() end
}
copas.loop()