Page 1 of 1

set en restore a setting

Posted: Monday 24 August 2020 11:45
by kroonp
I want to achieve the following. A hue lamp is on in a certain color. As soon as the doorbell rings, I switch on a different color for a minute. I want to go back to the first situation after that.
This works but restoring to the original color is not possible. Is there a way to save and restore the original color in dzvents?

Re: set en restore a setting

Posted: Monday 24 August 2020 12:56
by waaren
kroonp wrote: Monday 24 August 2020 11:45 I want to achieve the following. A hue lamp is on in a certain color. As soon as the doorbell rings, I switch on a different color for a minute. I want to go back to the first situation after that.
This works but restoring to the original color is not possible. Is there a way to save and restore the original color in dzvents?
Seems to be similar question as in this topic

Re: set en restore a setting

Posted: Monday 24 August 2020 17:35
by kroonp
Ik viewed the topic.
What kind of devices are safeColor and getColor ??

return {
on = { devices = { "safeColor","getColor"}} ,

Re: set en restore a setting

Posted: Monday 24 August 2020 17:42
by waaren
kroonp wrote: Monday 24 August 2020 17:35 Ik viewed the topic.
What kind of devices are safeColor and getColor ??

return {
on = { devices = { "safeColor","getColor"}} ,
These are dummy switches to trigger the script. The script is a proof of concept and needs to be adjusted for your situation.
The important parts are the data section and the functions in the execute section

Happy to help if you give me the name, type and subtype of the bel and light involved and the script you have so far.

Re: set en restore a setting

Posted: Monday 24 August 2020 18:01
by kroonp
Thanks for helping me.

I used the script as shown above

Mijn colorwitch: Keuken idx 31
My bel is : Doorbell idx 265


Code: Select all

-- KeepRestoreRGB

return {
    on =        {   devices                 = { "safeColor","getColor"}}  ,

    data    =   {   previousColor           = { initial = {} },
                    previousBrightness      = { initial = -1  }},
    
    logging =   {   level                   = domoticz.LOG_DEBUG,
                    marker                  = "KeepRestoreRGB" },
                        
    execute = function(dz, item)
        local rgbLight = dz.devices(31) --  This is the light bulb
        
        local function internalURL(url)
            dz.openURL({
                            url = dz.settings['Domoticz url'] .. url,
                            method = "GET",
                        })
        end
        
        local function setColor(idx,color,brightness) 
            myUrl =  "/json.htm?type=command&param=setcolbrightnessvalue&" .. 
                    "idx=" .. idx .. 
                    "&color=" .. color ..
                    "&brightness=" .. brightness
            internalURL(myUrl)
        end

        if item.name == 'safeColor' or dz.data.previousBrightness == -1 then
            dz.data.previousColor       = dz.utils.fromJSON(rgbLight.color) -- Safe current color in dzVents persistent data
            dz.data.previousBrightness  = rgbLight.level                    -- Safe current brightness in dzVents persistent data
        elseif item.name == "getColor" then
            setColor(rgbLight.idx, dz.utils.toJSON(dz.data.previousColor), dz.data.previousBrightness)
        end
    end
}

Re: set en restore a setting

Posted: Monday 24 August 2020 19:44
by kroonp
It works, thankx

Re: set en restore a setting

Posted: Tuesday 25 August 2020 9:38
by kroonp
I thought all the settings were good.
I made 2 dummy swichtes safeColor and getColor.
The script works. The current situation is saved when I push the switch safeColor and can be retrieved with i push the swicht getColor.
So fine. I now wanted to process it in the script below, but I make something wrong there. When the Keuken (31) is on and I push switch test nothing happens. The light does not show te new color.

Code: Select all

return {
	on = {
		devices = {
			'test'
		}
	},
	execute = function(domoticz, device)
	  domoticz.devices('safeColor').swichtOn() -- save the color
	  domoticz.devices('Keuken').setRGB(255, 153, 153)-- set new color idx 31
	  domoticz.devices('getColor').swichtOn().afterSec(5) -- get saved color after 5 seconds.
	end
}

Re: set en restore a setting

Posted: Tuesday 25 August 2020 15:32
by waaren
kroonp wrote: Tuesday 25 August 2020 9:38 I now wanted to process it in the script below, but I make something wrong there. When the Keuken (31) is on and I push switch test nothing happens. The light does not show te new color.
You made a typo. the method is switchOn() and you typed switchtOn()