Page 1 of 1

No presence and alarm still disabled warning

Posted: Sunday 02 May 2021 10:48
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
}

Re: No presence and alarm still disabled warning

Posted: Sunday 02 May 2021 21:02
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.

Re: No presence and alarm still disabled warning

Posted: Monday 03 May 2021 9:40
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!