I was hoping to present a nice clean script with fabulous options, but it takes me much longer than expected and there is so much to do and the weather is nice and ...
Anyway, the core is this (this is just a test script, you will have to change it to make it work for you):
Code: Select all
return {
on = {
devices = {
2418 -- virtual test button
},
httpResponses = {
'HUE_DYNAMIC_SCENES'
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "HUE_DYNAMIC_SCENES"
},
execute = function(domoticz, triggerItem)
local myHueBridgeIp = domoticz.helpers.myHueBridgeIp
local myHueApiKey = domoticz.helpers.myHueApiKey
local myHueTestscene = 'cc28d5cb-e381-4336-ae1d-6fba567c955b'
if (triggerItem.isDevice) then
domoticz.log('Script started, trigger = '.. triggerItem.name , domoticz.LOG_DEBUG )
domoticz.openURL({
url = 'https://' .. myHueBridgeIp .. '/clip/v2/resource/scene/' .. myHueTestscene,
method = 'PUT',
callback = 'HUE_DYNAMIC_SCENES',
headers = {
['hue-application-key'] = myHueApiKey
},
postData = {
recall = {
['action'] = 'dynamic_palette'
}
}
})
elseif (triggerItem.isHTTPResponse) then
domoticz.log('Script started, trigger = HTTPResponse' , domoticz.LOG_DEBUG )
local response = triggerItem
if ( response.ok and response.isJSON ) then
domoticz.log('Command OK', domoticz.LOG_DEBUG )
else
domoticz.log('Command not ok', domoticz.LOG_DEBUG )
response.dump()
end
end
end
}
It uses the new HUE API Version 2, which is really different from the previous version. It took some experimenting.
myHueBridgeIp obviously is the ip address of your HUE bridge.
myHueApiKey is the api-key you
get from the bridge.
myHueTestscene is the API v2 ID of the HUE scene you want to activate. You can find the scenes with the API Clip debugger:
In a browser goto
https://yourbridgeip/debug/clip.html
Enter in the URL field :
https://yourbridgeip/clip/v2/resource/scene
In Headers on the left side "hue-application-key" , without the "".
In the field next to it enter your api key
Then click GET
The Command response field spits out a lot of info. You want to look for parts that look like this:
Code: Select all
"id": "cc28d5cb-e381-4336-ae1d-6fba567c955b",
"id_v1": "/scenes/BghBTO8dK9lrmtA",
"metadata": {
"image": {
"rid": "d271d202-6856-4633-95ae-953ba73aee64",
"rtype": "public_image"
},
"name": "Honolulu"
},
So, the id for scene Honolulu is cc28d5cb-e381-4336-ae1d-6fba567c955b
Good luck