Intruder alert script  [Solved]

Post Reply
Posts: 167
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 2.3852
Location: Spain

Intruder alert script

Post by elmortero » Saturday 17 December 2016 14:12

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)
		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)
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=""

                        if (device.description ~= nil) then
                                _, _, threshold = string.find(device.description,"CDA:(%d+)")
                                if (threshold ~= nil) then
                                        local 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'

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

Posts: 1293
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo

Re: Intruder alert script  [Solved]

Post by dannybloe » Wednesday 21 December 2016 14:23

It should pass the device that caused the trigger as the second argument to you execute function.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest