Page 1 of 1

Who can help me with dzvents scripts?

Posted: Tuesday 19 March 2019 16:40
by yazoo
What do i want?

i have a on/off switch in the toilet and i want that the switch when i turn it on automatically turn off in 10 minutes.
who can help me with a dzVets script for wat i want.

Re: Who can help me with dzvents scripts?

Posted: Tuesday 19 March 2019 16:45
by emme

Code: Select all

local mySwitch = '<put here your switch Device Name>'
local minDelay = 10

return {
        on = {
         devices = { mySwitch }
       },

        execute = function(dz, mySw)
			if mySw.state == 'On' then
				dz.devices(mySwitch).switchOff().afterMin(minDelay)
			elseif  mySw.state == 'Off' then
				dz.devices(mySwitch).cancelQueuedCommands()
			end if 
        end
    }
this way you ask Dz to switch of the light after 10 minutes, but if you switch it of manually it cancel the queued message so, the next time you switch it back on the 10 minutes countdown will restart

Re: Who can help me with dzvents scripts?

Posted: Tuesday 19 March 2019 17:15
by yazoo
emme wrote: Tuesday 19 March 2019 16:45

Code: Select all

local mySwitch = '<put here your switch Device Name>'
local minDelay = 10

return {
        on = {
         devices = { mySwitch }
       },

        execute = function(dz, mySw)
			if mySw.state == 'On' then
				dz.devices(mySwitch).switchOff().afterMin(minDelay)
			elseif  mySw.state == 'Off' then
				dz.devices(mySwitch).cancelQueuedCommands()
			end if 
        end
    }
this way you ask Dz to switch of the light after 10 minutes, but if you switch it of manually it cancel the queued message so, the next time you switch it back on the 10 minutes countdown will restart
Thanks emme for the script,
I test the script i put it like this see below end its working now.

local mySwitch = 'Hue Eetkamer tafel Lamp'
local minDelay = 1

return {
on = {
devices = { mySwitch }
},

execute = function(dz, mySw)
if mySw.state == 'On' then
dz.devices(mySwitch).switchOff().afterMin(minDelay)
elseif mySw.state == 'Off' then
dz.devices(mySwitch).cancelQueuedCommands()
end
end
}

Re: Who can help me with dzvents scripts?

Posted: Tuesday 19 March 2019 17:33
by emme
oops!... forgot an "end" :P

this is usually my signature in the scripts :D :D :D