EvertJob

Untitled

Jan 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | None | 0 0
  1. local devicesToCheck = {
  2. --  table with doors to check and the minutes before the first warning is given
  3.     { ['name'] = 'Xiaomi Tuindeur links', ['threshold'] = 3 },
  4.     { ['name'] = 'Xiaomi Tuindeur rechts', ['threshold'] = 10 },
  5.  
  6. }
  7. --  number of times you are warned about an open door
  8. local alertCount = 3
  9.  
  10. return {
  11.     active = true,
  12.    
  13.     on = {
  14.         timer = {'every 5 minutes'},
  15.     },
  16.     logging = {
  17. --        level = domoticz.LOG_INFO,
  18.         marker = "POR"
  19.     },    
  20. --  count per door of the number of alerts per door
  21.     data = {
  22.         ['Xiaomi Tuindeur links'] = {initial=0},
  23.         ['Xiaomi Tuindeur rechts'] = {initial=0},
  24.      
  25.         },
  26.  
  27.     execute = function(domoticz)
  28.         for i, deviceToCheck in pairs(devicesToCheck) do
  29.             local name = deviceToCheck['name']
  30.             local threshold = deviceToCheck['threshold']
  31.             local state = domoticz.devices(name).state
  32.             local minutes = domoticz.devices(name).lastUpdate.minutesAgo
  33.             if ( state == 'Open') then
  34.                 domoticz.log('Device ' .. name .. ' staat  ' .. minutes .. ' minuten open.')
  35.                 if (minutes > threshold and domoticz.data[name] < alertCount) then
  36.                     domoticz.data[name] = domoticz.data[name] + 1
  37.                     domoticz.notify("Domoticz", name .. " staat al langer dan " .. minutes .. " minuten open.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , "telegram")
  38.                     domoticz.log('dit is waarschuwing ' .. tostring(domoticz.data[name]))
  39.                 end
  40.             elseif (domoticz.data[name] > 0) then
  41.                 domoticz.notify("Domoticz", name .. " staat al langer dan " .. minutes .. " minuten open.", domoticz.PRIORITY_NORMAL,ddomoticz.SOUND_DEFAULT, "" , "telegram")
  42.                 domoticz.log('Device ' .. name .. ' is  ' .. minutes .. ' dicht.')
  43.                 domoticz.data[name] = 0
  44.             end
  45.         end
  46.     end
  47. }
Advertisement
Add Comment
Please, Sign In to add comment