No presence and alarm still disabled warning

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

Moderator: leecollings

Post Reply
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

No presence and alarm still disabled warning

Post by sammyke007 »

Hi

I'm looking to give me and my wife a warning through Telegram whenever we're both away and the alarm is not armed.

Is this correct? I can read and understand LUA / Dzvents, but writing it myself...

Switch IDX 394 is a presence dummy switch.

I also wish to send this warning only once, not again every minute as the value stays "true"... I hope this is scripted correct?

Code: Select all

return {
	active = true, 
	on = {
		timer = {
			'every minute',
		}
	},
	data = 
    	{
       		Alerts = { initial = 0 },
	}, 
	logging = 
    	{
        	level = domoticz.LOG_INFO,
        	marker = "AlarmPresenceCheck"
   	},   
	execute = function(domoticz, device)
		local switch = domoticz.devices(394)		-- virtual switch for presence
		if (switch.state == 'Off' and switch.lastUpdate.minutesAgo >= 30 and domoticz.security == domoticz.SECURITY_DISARMED and domoticz.data.Alerts == 0) then
		    domoticz.notify('AlarmCheck','Er is al ' .. switch.lastUpdate.minutesAgo .. ' minuten niemand thuis en het alarm staat nog uit!',domoticz.PRIORITY_HIGH,nil,nil,domoticz.NSS_TELEGRAM,0)
		    domoticz.data.Alerts = domoticz.data.Alerts + 1
		elseif (switch.state == 'Off' and switch.lastUpdate.minutesAgo >= 30 and domoticz.security == domoticz.SECURITY_DISARMED and domoticz.data.Alerts ~= 0) then
		    domoticz.log('Geen melding meer, counter staat al op ' ..domoticz.data.Alerts)
		else 
		    if (domoticz.data.Alerts ~= 0) then
		        domoticz.data.Alerts = 0
		        domoticz.log('Reset, counter staat terug op ' ..domoticz.data.Alerts)
		    else
		        domoticz.log('Niets te doen!')
		    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: No presence and alarm still disabled warning

Post by waaren »

sammyke007 wrote: Sunday 02 May 2021 10:48 I also wish to send this warning only once, not again every minute as the value stays "true"... I hope this is scripted correct?
Seems about right but best to test all scenarios before relying on it.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: No presence and alarm still disabled warning

Post by sammyke007 »

It warned me this morning as it should after 30 minutes.
The coding might not be 100% like it should be, but hey, it works :-D.
Tnx for looking into it waaren!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest