Page 1 of 1

[Solved] How to activate HUE dynamic scenes?

Posted: Sunday 06 February 2022 16:34
by Sarcas
Does anyone know how to activate the new HUE dynamic scenes? The scene-devices created by the HUE plugin just activate the static version.

Thx

Edit:
I figured it out. Will post if anyone is interested.

Re: [Solved] How to activate HUE dynamic scenes?

Posted: Tuesday 15 February 2022 19:10
by gomario
Well, you might as well share with the class:) Thanks

Re: [Solved] How to activate HUE dynamic scenes?

Posted: Monday 07 March 2022 18:09
by lholwerda
can you please let us know how you splved this?

Re: [Solved] How to activate HUE dynamic scenes?

Posted: Thursday 10 March 2022 16:23
by Sarcas
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 :)