Delay for PIR?  [Solved]

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

Moderator: leecollings

Post Reply
johansson
Posts: 75
Joined: Sunday 27 September 2015 15:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Finland
Contact:

Delay for PIR?

Post by johansson »

I've a couple of motion detectors that send snapshots to Telegram when motion is detected. The basic setup works nicely, but motion is detected a bit too far away: how to add a delay in dzvents scrip?

The current script below. Eg, adding ".afterSec(1)" after the os.execute does not work.

Code: Select all

return {
	on = {
		devices = {
			'Motion detector 1',
		}
	},
	execute = function(dz, device)
 local securityArmed = (dz.security == dz.SECURITY_ARMEDAWAY or dz.security == dz.SECURITY_ARMEDHOME)
        if device.active and securityArmed then 
   		os.execute('sudo /home/folder/to/scripts/snapshot.sh &')

end
end
}
Another option would also be recording a short video clip to my Raspberry in addition to the snapshot, but that I couldn't figure out either.

Any ideas? Thanks in advance.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Delay for PIR?

Post by waaren »

johansson wrote: Friday 13 March 2020 14:08 I've a couple of motion detectors that send snapshots to Telegram when motion is detected. The basic setup works nicely, but motion is detected a bit too far away: how to add a delay in dzvents script?
If the delay is only 1 second, my approach would be

Code: Select all

return {
    on = {
        devices = {
            'Motion detector 1',
        }
    },
    execute = function(dz, device)
        local securityArmed = (dz.security == dz.SECURITY_ARMEDAWAY or dz.security == dz.SECURITY_ARMEDHOME)
        if device.active and securityArmed then 
            os.execute('sleep 1; sudo /home/folder/to/scripts/snapshot.sh &')
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
johansson
Posts: 75
Joined: Sunday 27 September 2015 15:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Finland
Contact:

Re: Delay for PIR?  [Solved]

Post by johansson »

Oh yes, simple and beautiful! Works like charm, thanks a bunch.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest