I need help getting a garage door close using a selector
Posted: Thursday 18 July 2019 23:29
What I am trying to do is watch for the garage door tilt sensor to turn on, once it does it will look at the selector in domoticz and see how long it needs to stay open. Then will wait the required time and close the door. If the selector is off it ignores the timer commands and stays open. Can someone point out my mistakes or tell me if this is possible.
Code: Select all
-- DZVents script to control garage door open time
local selector = 'Garage Door Close Timer' -- virtual timer switch
local switch = 'Garage Door Opener' -- garage door opener
local variable = 'Garage Timer Minutes Set' -- variable from virtual switch
local tilt = 'Garage Door Tilt Sensor' -- tilt sensor to determine open or closed
return {
on =
{
devices =
{
selector, -- Selector switch ( set timer )
},
variables =
{
variable
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(domoticz, item)
selector = domoticz.devices(selector)
switch = domoticz.devices(switch)
variable = domoticz.variables(variable)
local function stop(reason)
domoticz.log("Closing garage door triggered by " .. reason,domoticz.LOG_DEBUG)
variable.cancelQueuedCommands()
variable.set(0).silent()
switch.switchOff().silent()
selector.switchSelector(0).silent()
end
if tilt.levelName == 'On' then
if item.isVariable then
if item.value > 0 then
item.cancelQueuedCommands()
item.set(0).afterMin(item.value) -- This will trigger script again after the set minutes
domoticz.log("Garage door will be open for " .. item.value .. " minutes")
switch.switchOn().silent() else
stop("variable =< =") -- var 0 ==> close garage door
end
elseif item == selector then
if item.level == 0 then stop("selector set to 0")
elseif item.level < 70 then variable.set(item.level)
elseif item.level == 70 then variable.set(120)
elseif item.level == 80 then variable.set(240)
end
item.switchSelector(0).silent()
elseif not(item.active) then
stop("manually (or timer) closed control switch") -- selector or switch set to Off
end
end
end
}