Page 1 of 1

sleep/wait in a script?

Posted: Tuesday 08 August 2017 15:51
by TheCondor
Hello, there's nothing similar to a wait or sleep before trigger a switch-on?
I wrote this simple script that turn on the alarm when the tag-presence (a bluetooth beacon) is "out-house" (Fuori) and turn it of when is "in-house" (Casa):

Code: Select all

..... ON 'Tag_Andrea' variable state changed......

 if domoticz.variables('Tag_Andrea').value == 'Fuori' then
            domoticz.devices('Pannello Allarme').armAway()
 elseif domoticz.variables('Tag_Andrea').value == 'Casa' then
            domoticz.devices('Pannello Allarme').disarm()
        end
It works fine but i wanna refine more and ad a -wait- or a -sleep- before turn on the alarm for when i'm leaving b house for exable for going in the garden downside or in the card and i'll come back few minutes later.

Code: Select all

if domoticz.variables('Tag_Andrea').value == 'Fuori' then
	 CREATE A LOCAL VARIABLE AND SET IT TO 'FUORI'
	 SLEEP 20 MINUTES
	 IF LOCAL_VARIABLE.STATE == domoticz.variables('Tag_Andrea').state then
            domoticz.devices('Pannello Allarme').armAway()
         ELSE DO NOTHING BECAUSE I'M IN HOUSE AGAIN
            

Any suggest? Thanks in advance for your kind help!

Re: sleep/wait in a script?

Posted: Tuesday 08 August 2017 16:06
by freijn
What about this ( as you are thinking in minutes )

Set a variable when the trigger starts. Variable can contain a timestamp
Check every minute if this variable is still "hot" then after 5 min difference ( current_time-Var_time > 5 ) you activate the alarm.

Re: sleep/wait in a script?

Posted: Tuesday 08 August 2017 16:12
by jvandenbroek
Not checked / tested it myself, but can't you just use armAway().afterMin(20)?

Re: sleep/wait in a script?

Posted: Tuesday 08 August 2017 16:59
by heggink
AfterSec and such work. Used it myself. Please note that there is the delay in settings that is also used. Please also note that during the delay, domoticz.security will already say "armed..". Have a look at the new dzvents proposed alarm scripts.

Re: sleep/wait in a script?

Posted: Thursday 10 August 2017 15:46
by TheCondor
current_time - Var_time could work... AfterSec is triggered in "advance" and cannot be deleted if an opposite event is triggered.
I explain better:

if TAG_PRESENCE = OUT then
security.panel = ON after 2 minute <---- (it will be turned on after 2 minute anyway, also if TAG_PRESENCE will turn = IN before the 2 minute delay).

So, if i understood well the AfterSec the only way is trough a local variable of a time difference. But maybe this could be integrated in DZVENTS next build with a SLEEP XX SECONDS to write -BEFORE- the SecurityPanel = ON command and recheck again the TAG_PRESENCE and if still = OUT THEN, and only now, turn on the alarm. This could be useful in other situations obviously....

Re: sleep/wait in a script?

Posted: Friday 11 August 2017 20:51
by heggink
So you're saying that an armAway.Aftersec(90) still arms even if within the 90 secs a disarm is done? That's not helpful...

Re: sleep/wait in a script?

Posted: Tuesday 15 August 2017 14:27
by jeanclic
Hello,

I'm wokring on an alarm script, and I have seen a lot of topics talking about this delay "issue" (I mean the security state beeing "Armed" immediately despite the delay in the settings).

I have seen a lot of scripts defining a variable containing a time to delay the actions.
Would it not be easier to have a mean via dzVents to access the domoticz settings, and so get the time directly from the settings ? (accessible via /json.htm?type=settings -> item "SecOnDelay") ?
Maybe it is already the cas,but I did not found it...

-> begining with this info, I assume it would be easy to have the "alarm" script acting only when "Armed" for at least the time in settings ?