sleep/wait in a script?

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

Moderator: leecollings

Post Reply
TheCondor
Posts: 78
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

sleep/wait in a script?

Post 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!
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: sleep/wait in a script?

Post 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.
jvandenbroek
Posts: 37
Joined: Wednesday 12 March 2014 16:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: sleep/wait in a script?

Post by jvandenbroek »

Not checked / tested it myself, but can't you just use armAway().afterMin(20)?
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: sleep/wait in a script?

Post 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.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
TheCondor
Posts: 78
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: sleep/wait in a script?

Post 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....
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: sleep/wait in a script?

Post 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...
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
jeanclic
Posts: 68
Joined: Saturday 28 January 2017 11:32
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France / Burgundy
Contact:

Re: sleep/wait in a script?

Post 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 ?
RPI3B (Domoticz 4.9700 + ~60 scripts) + RFXtrx433E (fw1020) + Z-Stick Gen5 + MySensors / RPI2B+ (RasPlex)
x1 Eth. wired tablet
x8 T/H Oregon / x1 T/H Bresser
x7 heaters / x2 QUBINO "Flush 1 relay"
x10 plugs / x15 contacts
x4 fibaro / x1 PIR
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest