set en restore a setting

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

set en restore a setting

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: set en restore a setting

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: set en restore a setting

Post by kroonp »

Ik viewed the topic.
What kind of devices are safeColor and getColor ??

return {
on = { devices = { "safeColor","getColor"}} ,
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: set en restore a setting

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: set en restore a setting

Post 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
}
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: set en restore a setting

Post by kroonp »

It works, thankx
kroonp
Posts: 43
Joined: Friday 17 July 2020 11:03
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: set en restore a setting

Post 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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: set en restore a setting

Post 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()
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest