EvertJob

Deursensoren

Jan 24th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.43 KB | None | 0 0
  1. local devicesToCheck = {
  2.     {
  3.         ['name']        = 'Test',       --Geef hier de naam van het apparaat op
  4.         ['startAfter']  = 0,            --Na hoeveel minuten moet de eerste waarschuwing komen?
  5.         ['warnings']    = 3             --Hoeveel waarschuwingen wil je ontvangen?
  6.     },{
  7.         ['name']        = 'Test2',
  8.         ['startAfter']  = 0,
  9.         ['warnings']    = 4
  10.     }
  11. }
  12.  
  13. local messageWarnings = {
  14.         ['0']           = 'eerste waarschuwing',
  15.         ['1']           = 'tweede waarschuwing',
  16.         ['2']           = 'derde waarschuwing',
  17.         ['3']           = 'vierde waarschuwing',
  18.         ['4']           = 'vijfde waarschuwing'
  19. }
  20.  
  21. return {
  22.    on = {
  23.      timer            = { 'every 5 minutes' },
  24.    },
  25.    data = {
  26.       ['Test']          = { initial=0 }, --Voer hier EXACT de zelfde namen als boven in (in devicesToCheck) in!
  27.       ['Test2']         = { initial=0 }
  28.    },
  29.    execute = function(domoticz)
  30.  
  31.        for i, deviceToCheck in pairs(devicesToCheck) do
  32.            
  33.            local deviceName             = deviceToCheck['name']
  34.            local numberOfWarnings       = deviceToCheck['warnings']
  35.            local currentDeviceState     = domoticz.devices(deviceName).state
  36.            local lastDeviceUpdate       = domoticz.devices(deviceName).lastUpdate.minutesAgo
  37.            local minutesToWait          = deviceToCheck['startAfter']
  38.            local deviceCounted          = domoticz.data[deviceName]
  39.  
  40.            if ( currentDeviceState == 'Open') then
  41.                
  42.                     if(deviceCounted < numberOfWarnings and lastDeviceUpdate >= minutesToWait) then
  43.                         domoticz.notify("Domoticz", deviceName .. " staat al " .. lastDeviceUpdate .. " minuten open. Dit is de "..messageWarnings[''..deviceCounted..''].."", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , "telegram")
  44.                     end
  45.                
  46.                domoticz.data[deviceName] = domoticz.data[deviceName] + 1
  47.          
  48.             elseif( currentDeviceState == 'Closed' and deviceCounted > 0) then
  49.            
  50.                 domoticz.data[deviceName] = 0
  51.                 domoticz.log("De deur is dicht")
  52.                
  53.                 domoticz.notify("Domoticz", deviceName .. " is al " .. lastDeviceUpdate .. " minuten dicht.", domoticz.PRIORITY_NORMAL,domoticz.SOUND_DEFAULT, "" , "telegram")
  54.                
  55.            end
  56.  
  57.        --end
  58.        end
  59.    end
  60. }
Advertisement
Add Comment
Please, Sign In to add comment