Intruder alert script  [

elmortero
Posts: 97
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 2.3852
Location: Spain
Contact:

Intruder alert script

Postby 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)
      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.

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

Re: Intruder alert script  [

Postby 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 - RPiB+ZWay - Aeotec MultiSensor (6x) - Fibaro/Popp/GreenWave wall plugs - TKB Home dimmer - Aeotec Door sensor - Toon - 2x FGD-212, 8x FGD-211, 3x Qubino Flush dimmers - EvoHome Wifi+HGI80 - ESPEasy


Return to “dzVents Lua Framework”

Who is online

Users browsing this forum: No registered users and 1 guest