Page 1 of 1

"If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 01 September 2019 15:40
by fotomann100
I'm not able to find a programming solution for the following problem:

I would like to control the status of a garage door. If the door is open for more than ten minutes, Domoticz should send a message via Pushbullet.

I have got a switch, that indicates the door status. Sending a message after ten minutes is also no problem. But the message is sent out also if the door is closed before the ten minutes.

How can I program this right?

Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 01 September 2019 16:50
by jvdz
Show the script you have to send the message out please so we can see what you are doing, but my guess is your aren't testing the actual switch status.

Jos

Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 01 September 2019 17:47
by fotomann100
I have got several versions of the program with the common ground that they do not work. In the try listed below I'am using a user variable that is set to "1" after 600 seconds.

The notification is sent, when the door status is changing from open to close. There is also a problem with the trigger, the 2. Else-if-part is not executed. In result, the user variable stays in status "1".

Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 01 September 2019 20:04
by jvdz
It will never reach the second condition as the first one is valid when the status changes to Open.
I am always using LUA scripts for logic like this, or you could use dzEvent as well as that is also easy to test for the time the switch changed last.

Jos

Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 01 September 2019 20:54
by lost
fotomann100 wrote: Sunday 01 September 2019 15:40 How can I program this right?
I have done such function, in Lua, a 'bit more complex': Send a mail notification if we are present & auto-close the door if we are not (linked with domoticz security panel status/alarm function) + garage PIR did not trigger since some time (as a security even if door have it's own), in case my children forget to close after leaving with their bicycles...

Code snippet from a lua time script managing several 'simple' functions :

Code: Select all

--
-- Garage door editable settings :
--
devGarageDoorState ='SectGarage'
devGarageDoorCmd   ='CdeSectGge'
devGarageSensMvt   ='MvtGarage'

garageNoMvtSec=30
garageNoMvtAdv=120
garageNoStaSec=180
garageDoorCloseTimeSec=60

-- To be used by checks that do not have to be handled every minute...
CurrentMn = os.date('%M')

--(...)

------------------------
-- GARAGE DOOR CHECKS --
------------------------

-- print('Porte Garage : '..otherdevices[devGarageDoorState])

-- Only check every 5 mn
if ((CurrentMn % 5 == 0) and (otherdevices[devGarageDoorState] == 'Open')) then
    lastMvt=timeLastUpdate(devGarageSensMvt)
    lastCmd=timeLastUpdate(devGarageDoorCmd)
    lastSta=timeLastUpdate(devGarageDoorState)
    
    if ((lastMvt >  garageNoMvtSec) and (lastSta > garageNoStaSec) and (lastCmd >  garageDoorCloseTimeSec)) then
        if (otherdevices[devSecPanel] == 'Arm Away') then
            -- Auto off after 1s set in switch properties
            print('Sending auto-close for '..devGarageDoorCmd..' after no mvt for '..lastMvt..'s & no cmd for '..lastCmd..'s.')
            cmdNb = cmdNb + 1
            commandArray[cmdNb]={[devGarageDoorCmd]='On'}
        else
            if (lastMvt >  garageNoMvtAdv) then
                cmdNb = cmdNb + 1
                commandArray[cmdNb]={['SendEmail'] = 'OUBLI GARAGE ?#'..devGarageDoorState..' : '..otherdevices[devGarageDoorState]..' since '..lastSta..'s ; '..os
.date("%c")..'#'..emailNotifyAlarm}
            end
        end
    end
    
    print('Porte Garage ouverte depuis '..lastSta..'s, dernier mvt/cmd : '..lastMvt..'/'..lastCmd..'s.')
end

--(...)

--------------------------
-- THAT'S ALL FOLKS !!! --
--------------------------

return commandArray


Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 01 September 2019 22:21
by fotomann100
Hello lost,
thank you for the advice and the code snippet. Tomorrow I will try to understand how it works - sounds interesting.
In the meantime - thank you jvdz - I developed the blockly script and extended it by a dummy switch as a timer: It seems to work, but there is one problem, that I do not understand:

The yellow marked middle part of the script is ignored by domoticz and I don't know why.

Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Monday 02 September 2019 1:14
by felix63
I use a dzvents script that I adapted from somewhere. See this thread: https://www.domoticz.com/forum/viewtopi ... 72&t=23768

Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 09 May 2021 17:32
by joshua1
I have done it this way, works o.k.

Re: "If the door is open for more than ten minutes --> Send message. Advice needed

Posted: Sunday 12 June 2022 20:55
by Refhi
joshua1 wrote: Sunday 09 May 2021 17:32 I have done it this way, works o.k.
I... I don't understand how that work, but it does !

Well done. And thanks.