This is work in progress, so any suggestions / help most welcome. This post assumes you understand how to interact with Hue lights and have installed the socket library from Zerobrane, I will document fully when complete.
Currently, I just wanted to show what is possible, as I have managed to use Lua with the Lua sockets library to control the Philips Hue lights.
The script below demonstrates what is possible, if you have a number of Hue light, then using this script and just creating dummy switches in Domoticz called Hue1, Hue2, Hue3, ...., you will be able to turn the lights on and off.
Code: Select all
-- ~/domoticz/scripts/lua/script_device_hue.lua
-- Simple script to turn on and off Philips Hue lights
-- For each of your Philips Hue lights you need to create a dummy switch named: HueXanythingatall
-- where x is the number of your light, e.g. Hue3Lounge would control Hue light 3
-- Ensure that you have registered the user with the Philips Hue bridge
-- N.B. one wrongly named Hue dummy switch may stop the script, check log for any issues
commandArray = {}
io = require('io')
http = require('socket.http')
ltn12 = require('ltn12')
base_url = 'http://192.168.1.70/api/newdeveloper/'
function hueit(device, operation)
local url = base_url .. device
print('About to try')
print(url)
--local req_body = '{"on":true}'
local req_body = operation
local headers = {
["Content-Type"] = "application/x-www-form-urlencoded";
["Content-Length"] = #req_body;
}
client, code, headers, status = http.request{url=url, headers=headers, source=ltn12.source.string(req_body), method='PUT'}
print('Tried')
print(status)
return
end
tc=next(devicechanged)
v=tostring(tc)
if (v:sub(1,3) == 'Hue') then
print(v..' spotted')
device = 'lights/' .. v:sub(4,4) .. '/state'
if(devicechanged[v] =='On') then
hueit(device, '{"on":true}')
else
hueit(device, '{"on":false}')
end
end
return commandArray
So gHue1 would set the green level of the Hue light 1, rHue1 and bHue1 would then give the full colours for Hue light 1. I just need to understand the colour model used by the Hue lights and translate this into Lua.
I hope that while this will be rather clunky for setting colours interactively, that combining these switches and dimmers in scenes with preset level, it will be possible to create a numbers of scenes which allow rapid switching of a set of Hue lights' properties.