Page 1 of 1

Intruder alert script

Posted: Saturday 17 December 2016 13:12
by elmortero
I am using the example script "intruder alert.lua" as a template for a door/window opened script.

Code: Select all

return {

	active = true,

	on = {
		'dt*' -- all door contacts (
	},  
	execute = function(domoticz, detector)
	local away = domoticz.devices['Holiday']
		if (detector.state == 'Open' and away.state == 'On') then			-- a door/window was opened while we are away
			-- send notification
			domoticz.notify('Security breach', '', domoticz.PRIORITY_EMERGENCY)
		end
		
		else 
		if (detector.state == 'Open' and away.state == 'Off') then			-- a door/window was opened while we are home
			-- send notification
			domoticz.notify('DT ', 'But that is ok, we are home', domoticz.PRIORITY_LOW)
		end
		
}
Since the ON device contains a joker, how could I read the actual device that triggered the script so that I could include it in the notification like

Code: Select all

			domoticz.notify('Security breach', .. dtX ..'was opened while we are not home', domoticz.PRIORITY_EMERGENCY)
without having to add all the dt devices individually?

I think I should be able to base it on

Code: Select all

                local message=""

                domoticz.devices.forEach(function(device)
                        if (device.description ~= nil) then
                                _, _, threshold = string.find(device.description,"CDA:(%d+)")
                                if (threshold ~= nil) then
                                        local name = device.name
                                        local minutes = domoticz.devices[name].lastUpdate.minutesAgo
                                        if ( minutes > tonumber(threshold)) then
                                                message = message .. 'Device ' ..
                                                name .. ' seems to be dead. No heartbeat for at least ' ..
                                                minutes .. ' minutes.\r'
                                        end
                                end

                        end
                end)
But I would like to only check the devices whose name starts with dt.

Re: Intruder alert script  [Solved]

Posted: Wednesday 21 December 2016 13:23
by dannybloe
It should pass the device that caused the trigger as the second argument to you execute function.