I need help getting a garage door close using a selector  [Solved]

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

Moderator: leecollings

Post Reply
rlschulz
Posts: 20
Joined: Sunday 25 October 2015 16:33
Target OS: Windows
Domoticz version: 3.5877
Contact:

I need help getting a garage door close using a selector

Post by rlschulz »

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

Re: I need help getting a garage door close using a selector

Post by waaren »

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

Code: Select all

-- 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rlschulz
Posts: 20
Joined: Sunday 25 October 2015 16:33
Target OS: Windows
Domoticz version: 3.5877
Contact:

Re: I need help getting a garage door close using a selector

Post by rlschulz »

Your code is so much cleaner than my mess!
I am getting this error. Thank you for all your help.

2019-07-18 17:06:20.979 (Z-Wave) Light/Switch (Garage Door Tilt Sensor)
2019-07-18 17:06:21.026 Status: dzVents: Info: Garage door: ------ Start internal script: Garage Door Timed Close: Device: "Garage Door Tilt Sensor (Z-Wave)", Index: 589
2019-07-18 17:06:21.026 Status: dzVents: Debug: Garage door: Processing device-adapter for Garage Door Close Timer: Switch device adapter
2019-07-18 17:06:21.026 Status: dzVents: Error (2.4.19): Garage door: An error occured when calling event handler Garage Door Timed Close
2019-07-18 17:06:21.026 Status: dzVents: Error (2.4.19): Garage door: ...ts/dzVents/generated_scripts/Garage Door Timed Close.lua:10: attempt to index global 'domoticz' (a nil value)
2019-07-18 17:06:21.026 Status: dzVents: Info: Garage door: ------ Finished Garage Door Timed Close
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: I need help getting a garage door close using a selector

Post by waaren »

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

Code: Select all

-- 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rlschulz
Posts: 20
Joined: Sunday 25 October 2015 16:33
Target OS: Windows
Domoticz version: 3.5877
Contact:

Re: I need help getting a garage door close using a selector  [Solved]

Post by rlschulz »

That worked perfectly. Thank you!
rlschulz
Posts: 20
Joined: Sunday 25 October 2015 16:33
Target OS: Windows
Domoticz version: 3.5877
Contact:

Re: I need help getting a garage door close using a selector

Post by rlschulz »

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

Re: I need help getting a garage door close using a selector

Post by waaren »

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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rlschulz
Posts: 20
Joined: Sunday 25 October 2015 16:33
Target OS: Windows
Domoticz version: 3.5877
Contact:

Re: I need help getting a garage door close using a selector

Post by rlschulz »

Other than the tilt sensor changes to off when it is closes I can't. It doesn't use the z-wave pieces as it can be done with the car remote.
Post Reply

Who is online

Users browsing this forum: Doler and 1 guest