Who can help me with dzvents scripts?

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

Moderator: leecollings

Post Reply
yazoo
Posts: 11
Joined: Tuesday 19 March 2019 16:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Who can help me with dzvents scripts?

Post 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.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Who can help me with dzvents scripts?

Post 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
The most dangerous phrase in any language is:
"We always done this way"
yazoo
Posts: 11
Joined: Tuesday 19 March 2019 16:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Who can help me with dzvents scripts?

Post 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
}
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Who can help me with dzvents scripts?

Post by emme »

oops!... forgot an "end" :P

this is usually my signature in the scripts :D :D :D
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest