I use Nexa LYCT-705 remote to control my Hue scenes. Guessing this is similar to Kaku, Coco?
Don't have any dimmers so I don't know what kind of values you get from the dimmer, but if you get percentage like 10, 20, 30 and so on this could be done with a little work.
Take a look at my scripts below, maybe you can use something there.
Had an issue with my Hue hub and needed to reset the hub and lost all my scenes. To prevent that in the future I wanted to have the most common Hue scenes values stored in Domoticz.
Also use this common scenes from different scripts so I wanted the scenes values in one place. This is how I did it.
Code: Select all
-- ~/domoticz/scripts/lua/functions.lua
local b = {}
-- Philips Hue bridge settings
local HueBridgeIP = "192.168.X.X"
local HueBridgeAPI = "XXXXXX"
-- Philips Hue light ID settings
function b.PhilipsHueID(light_id)
if light_id == "LivingRoom1" then light_id = 1 end
if light_id == "LivingRoom2" then light_id = 2 end
if light_id == "LivingRoom3" then light_id = 3 end
if light_id == "LivingRoom4" then light_id = 4 end
if light_id == "WorkRoom1" then light_id = 5 end
if light_id == "WorkRoom2" then light_id = 6 end
if light_id == "WorkRoom3" then light_id = 7 end
if light_id == "Hall1" then light_id = 8 end
if light_id == "Kitchen" then light_id = 10 end
if light_id == "AlertWorkRoom" then light_id = 13 end
if light_id == "AlertLivingRoom" then light_id = 14 end
return light_id
end
--Function for scene values
--light_id, state, bri, hue, sat, alert, colorType, colorTypeValue, effect
function b.PhilipsHueScenes(room, scene)
if (room == "Livingroom") then
if (scene == "Max") then
b.PhilipsHue("LivingRoom1", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("LivingRoom2", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("LivingRoom3", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("LivingRoom4", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
elseif (scene == "Relax") then
b.PhilipsHue("LivingRoom1", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
b.PhilipsHue("LivingRoom2", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
b.PhilipsHue("LivingRoom3", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
b.PhilipsHue("LivingRoom4", "true", 159, 10376, 201, "none", "xy", "[0.5282,0.3963]", "none")
elseif (scene == "MovieMode") then
b.PhilipsHue("LivingRoom1", "true", 29, 12205, 250, "none", "xy", "[0.5455,0.4148]", "none")
b.PhilipsHue("LivingRoom2", "true", 29, 12205, 250, "none", "xy", "[0.5455,0.4148]", "none")
b.PhilipsHue("LivingRoom3", "true", 6, 5249, 115, "none", "xy", "[0.4891,0.3702]", "none")
b.PhilipsHue("LivingRoom4", "true", 6, 5249, 115, "none", "xy", "[0.4891,0.3702]", "none")
commandArray['Movie mode']='On' --Movie mode switch
elseif (scene == "Off") then
b.PhilipsHue("LivingRoom1", "false")
b.PhilipsHue("LivingRoom2", "false")
b.PhilipsHue("LivingRoom3", "false")
b.PhilipsHue("LivingRoom4", "false")
end
--Turn off "Movie mode" if On and other than Movie mode selected
if (otherdevices['Movie mode'] == 'On' and scene ~= "MovieMode") then
commandArray['Movie mode']='Off'
print("Turn Off Movie mode")
end
elseif room == "Workroom" then
if (scene == "Max") then
b.PhilipsHue("WorkRoom1", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("WorkRoom2", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
b.PhilipsHue("WorkRoom3", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none")
elseif (scene == "Relax") then
b.PhilipsHue("WorkRoom1", "true", 126, 14130, 179, "none", "xy", "[0.4845,0.4144]", "none")
b.PhilipsHue("WorkRoom2", "true", 126, 14130, 179, "none", "xy", "[0.4845,0.4144]", "none")
b.PhilipsHue("WorkRoom3", "false")
elseif (scene == "Off") then
b.PhilipsHue("WorkRoom1", "false")
b.PhilipsHue("WorkRoom2", "false")
b.PhilipsHue("WorkRoom3", "false")
end
elseif room == "Kitchen" then
if (scene == "Max") then
b.PhilipsHue("Kitchen", "true", 254, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none") -- Kitchen max
elseif (scene == "Relax") then
b.PhilipsHue("Kitchen", "true", 130, 14920, 144, "none", "xy", "[0.4595,0.4105]", "none") -- Kitchen Relax
elseif (scene == "Off") then
b.PhilipsHue("Kitchen", "false")
end
end
end
--Turn on/off Philips Hue Scene lights
--light_id, state, bri, hue, sat, alert, colorType, colorTypeValue, effect
function b.PhilipsHue(light_id, state, bri, hue, sat, alert, colorType, colorTypeValue, effect)
if state == "false" then
os.execute ('curl -X PUT -d "{\\"on\\":false}" http://'..HueBridgeIP..'/api/'..HueBridgeAPI..'/lights/'..b.PhilipsHueID(light_id)..'/state')
elseif state == "true" then
os.execute ('curl -X PUT -d "{\\"on\\": '..state..', \\"bri\\": '..bri..', \\"hue\\": '..hue..', \\"sat\\": '..sat..', \\"alert\\": \\"'..alert..'\\",\\"'..colorType..'\\": '..colorTypeValue..', \\"effect\\": \\"'..effect..'\\"}" http://'..HueBridgeIP..'/api/'..HueBridgeAPI..'/lights/'..b.PhilipsHueID(light_id)..'/state')
end
end
-- Function for checking Philips Hue On/Off state
function b.GetHueState(light_id)
local json = require ("dkjson")
local tmpfile = '/tmp/hueLight_'..b.PhilipsHueID(light_id)..'.txt'
os.execute('curl -s http://'..HueBridgeIP..'/api/'..HueBridgeAPI..'/lights/'..b.PhilipsHueID(light_id)..' > '..tmpfile)
local file = io.open(tmpfile)
local content = file:read()
local obj, pos, err = json.decode (content, 1, nil)
if err then
print ("Error:", err)
else
hue_state=(obj.state.on)
end
file:close()
os.execute('rm -f '..tmpfile..'')
--print (content)
return (hue_state)
end
-- Function for Alarm lights
function b.AlarmLights(status)
if status == "RedAlert" then
b.PhilipsHue("AlertWorkRoom", "true", 254, 65527, 253, "lselect", "xy", "[0.6736,0.3221]", "none")
b.PhilipsHue("AlertLivingRoom", "true", 254, 65527, 253, "lselect", "xy", "[0.6736,0.3221]", "none")
commandArray['Variable:AlarmLights-RedAlert']='1'
print("AlarmLights: Red Alert")
-- Timelapse alert. Only active between kl. 7:00 - 23:45
elseif (status == "Timelapse" and uservariables["AlarmLights-RedAlert"] == 0 and minutesnow >= 420 and minutesnow <= 1425) then
b.PhilipsHue("AlertWorkRoom", "true", 1, 44554, 224, "select", "hs", "[0.2175,0.1298]", "none")
b.PhilipsHue("AlertLivingRoom", "true", 1, 44554, 224, "select", "hs", "[0.2175,0.1298]", "none")
print("AlarmLights: Timelapse")
elseif status == "Off" then
b.PhilipsHue("AlertWorkRoom", "false")
b.PhilipsHue("AlertLivingRoom", "false")
print("AlertLights: Turned off")
if uservariables["AlarmLights-RedAlert"] == 1 then
commandArray['Variable:AlarmLights-RedAlert']='0'
end
end
end
-- Function for time difference
function b.timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
return b