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.
-- 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
}
rlschulz wrote: ↑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.
If you enter the wait time in seconds as levelNames in the selector the script could look like
-- control garage door open time
return
{
on = { devices = { 'Garage Door Tilt Sensor'}},
logging = { level = domoticz.LOG_DEBUG, marker = 'Garage door' },
execute = function(dz, item)
local closeTimeSelector = dz.devices('Garage Door Close Timer')
local garagedoorSwitch = domoticz.devices('Garage Door Opener')
local closeTime = -1
if closeTimeSelector.state ~= 'Off' then
closeTime = tonumber(closeTimeSelector.levelName)
end
if item.active and ( closeTime > -1 ) then
garagedoorSwitch.switchOff().checkFirst().afterSec(closeTime)
end
end
}
Sorry, my mistake. I could only check syntax and domoticz / dzVents did not complain about this. Hope I understood your requirements and config though. Updated version below
-- control garage door open time
return
{
on = { devices = { 'Garage Door Tilt Sensor'}},
logging = { level = domoticz.LOG_DEBUG, marker = 'Garage door' },
execute = function(dz, item)
local closeTimeSelector = dz.devices('Garage Door Close Timer')
local garagedoorSwitch = dz.devices('Garage Door Opener')
local closeTime = -1
if closeTimeSelector.state ~= 'Off' then
closeTime = tonumber(closeTimeSelector.levelName)
end
if item.active and ( closeTime > -1 ) then
garagedoorSwitch.switchOff().checkFirst().afterSec(closeTime)
end
end
}
I ran into a different issue. If you close the garage door manually, the tilt sensor goes to off, but since it created a timer it will open the door again. Then it will wait the minutes set on the selector and close the door again. Is there a way if you close the door manually that it can cancel the timer?
rlschulz wrote: ↑Tuesday 30 July 2019 20:22
I ran into a different issue. If you close the garage door manually, the tilt sensor goes to off, but since it created a timer it will open the door again. Then it will wait the minutes set on the selector and close the door again. Is there a way if you close the door manually that it can cancel the timer?
If there is a way that domoticz can recognize the fact that you do some manual action then the script can be amended for it. Can you think of a way to set a virtual switch or userVariable if you do this manual action ?