Türen und Fenster überwachen

Ich hatte dieses Script auch als HC2 Version hier im Forum abgelegt finde es aber nicht mehr. Egal, da ist die HC3-Version. Die Portierungen sind nicht optimal aber die Scripte sind alle lauffähig.
Ich frage mich warum ich das Script jede Nacht um 03:05 neu starte. Aber habe das schon vor fast 1 Jahr so am laufen.
Und die Doku werde ich auch noch finden.

--[[
-- Conditions
{
  isTrigger = true,
  operator = "match",
  property = "cron",
  type = "date",
  value = { "5", "3", "*", "*", "*", "*" }
}

--]]
--
-- Scene File    : CheckDWinterval0.1.5.lua
-- Purpose       : Check doors and windows at the given interval.
-- Version       : 0.1.5-de
-- Release Date  : Mar.  2020
-- Trigger       : autostart
-- License       : Copyright {jwi} 

-- Either you enter all the door / window IDs in line 26, or you
-- let the script run in automatic mode. Save the line 26, so
-- you do not have to pick all the IDs again,

-- local sourceTrigger = fibaro.getSourceTrigger();
--local Debug = function ( color, message )  
-- fibaro.debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span") )
--end

local manually = false

local devices  = {48, 122, 202, 123, 127} --enter your device IDs here
local interval = 5   -- Interval after which the first push message is sent.
local version = '0.1.5' 
local hc = fibaro 

print( "Prüfe offene Türen und Fenster, version "..version)
if manually then
   prin( 'Manueller Modus aktiviert.')
else  
   devices = hc.getDevicesID({ enabled = true, visible = true, baseType = "com.fibaro.doorWindowSensor" })
   print('Automatischer Modus aktiviert.' )
end 
 

local numPushMsg  = 3    -- number of push messages
local pushAgain   = 3600 -- Activate pushMsg again after specified time.
local IDtempOut   = 80  -- IMPORTANT! ID of your outside temperatur sensor (e.g. Yahoo)
local TempOutType = 'value' --IMPORTANT 'Temperature' or 'value'
local excludedev  = {123,202,259,360} --This device(s) are exclcuded temporary from check
local ignoredev   = {568,566}      -- This devices are never checked
local begPeriod   = "07:00" -- During this period, no check is performed on the 
local endPeriod   = "20:15" -- sensors contained in the variable "excludedev".
local tThreshold  = 15   -- nn° Celsius 
local newInterval = 5    -- minutes to increase or decrease interval counter  
local phoneID     = {22} --  mobile-IDs 
local siren       = 398    -- Neo Coolcam optional device id for sound output after 'numPushMsg' 
local debug       = false  -- Debug messages yes/no 
local advdebug    = false  -- advanced debug
local soundOn     = false

-- No changes needed below this line.

local pushMsg = 1
local warning = 1
local counter = 0  
local lastopen = 0
local prevwarning = 0
local currInterval = 10

if (fibaro.getValue(IDtempOut, TempOutType)) == nil then
   print('Keine gültige Außentemperatur erkannt!')
   print('Bitte korrigieren. Szene wird abgebrochen!') 
  fibaro.scene("kill", {})
end    

local function excludecheck(excludedev, devid)
  if (os.date("%H:%M", os.time())) > begPeriod and (os.date("%H:%M", os.time())) < endPeriod then
     -- workaround for checking time after midnight
     -- or (os.date("%H:%M", os.time())) > "00:00" and (os.date("%H:%M", os.time())) < "06:30"  then
     for i=1,#excludedev do
        if excludedev[i] == devid then 
           return true
        end
     end --for
  end  
  return false
end

local function ignorecheck(ignoredev, devid)
  for i=1,#ignoredev do
        if ignoredev[i] == devid then 
           return true
        end
     end --for
  return false
end  

local function tempcheck()
  local outsideTemp = tonumber( fibaro.getValue(IDtempOut, TempOutType));
  local stringTemp = string.format("%.2f", outsideTemp)
  if outsideTemp > tThreshold then
      currInterval = interval + newInterval
    elseif  outsideTemp < tThreshold  then
      currInterval = interval - newInterval   
  else
      currInterval = interval    
  end  
  if (currInterval < 5) then 
     currInterval = 5
  end  
  return stringTemp, currInterval
end

local outsideTemp = tempcheck()
print("Check for open doors and windows... Version ".. version)
print("Außentemperatur ist " .. tempcheck() .. '°C')
print("Aktuelles Interval ist: " .. currInterval) 
if not debug then print('Debug ist ausgeschaltet.') end;

function checkOpenDW()
  local outsideTemp,currInterval = tempcheck()
  local currentDate = os.date("*t");
  local datum = os.date("%d.%m.%Y")
  counter = counter + 1
  devopen = 0
  for id = 1, #devices do
     if (fibaro.getValue(devices[id], 'value')) == true then
        local name  = fibaro.getName(devices[id])
        local room  = fibaro.getRoomNameByDeviceID(devices[id])
        if excludecheck(excludedev, devices[id]) ~= true 
           and ignorecheck(ignoredev,devices[id]) ~= true then  -- and
           devopen = devopen + 1
           status  = " ACHTUNG! " ..name.. " im Raum " ..room.. " ist offen! Temp. = "  .. outsideTemp.."°"
           print(datum .. status)
           warning = warning + 1
        end  
     end
            
     if (warning == prevwarning and warning > 0) then
         -- Tür wurde geschlossen
         warning = 1; counter = 1; prevwarning = 0; pushMsg = 1; 
     end     
    -- fibaro.trace("Scene12", "")
     if (warning == 0) then 
        -- Keine Tür geöffnet, Zähler beginnt von vorn 
         counter = 1; prevwarning = 0; pushMsg = 1; 
     end
      
     if (counter > currInterval+1 and warning > 0) then 
         -- Tür wurde geöffnet und wieder geschlossen, Warnungen werden zurückgesetzt   
         counter = 1; warning = 1; prevwarning = 0; pushMsg =1;
     end 
  end --for
  if devopen == 0 then
     counter = 1; warning = 1; prevwarning = 0; pushMsg =1;
     if debug then Debug('green', 'Alle Türen und Fenster geschlossen.') end;
  end  
  prevwarning = prevwarning +1  
  -- Tür/Fenster mehr als Interval-Min. offen. Meldung schicken 
  if counter > currInterval then
     if (devopen > 1) then
        status = status .. ' Total: '.. devopen 
     end
     if pushMsg <= numPushMsg then
        --print(datum .. ' Tür/Fenster seit mehr als '.. currInterval ..' Minuten geöffnet, sende Push Nr. '..pushMsg)
        fibaro.trace("Scene12", datum .. ' Tür/Fenster seit mehr als '.. currInterval ..' Minuten geöffnet, sende Push Nr. '..pushMsg)
        status = status .. ',Push-Nr.: ' .. pushMsg
        if pushMsg == numPushMsg then status = status ..' Letzte!' 
           lastopen = devopen
           if soundOn then
              -- fibaro.call(398, 'turnOn') --Siren / sounder
           end
        end
        pushMsg = pushMsg + 1
        uxtime = os.time(dt);
        for k=1, #phoneID do
           if phoneID[k] ~= nil then
              fibaro.call(phoneID[k], 'sendPush', status )
           end
        end --for
     end
     warning = 1; counter = 1; prevwarning = 0
  end 
   
  if advdebug then Debug('withe', 'Counter: '.. counter) end;
  if advdebug then Debug('withe', 'Warning: '.. warning) end;
  if advdebug then Debug('withe', 'PreWarning: '.. prevwarning) end;
  if advdebug then Debug('withe', 'PushMsg : '.. pushMsg) end;
  if advdebug then Debug('cyan', 'Device open: ' .. devopen) end
  if advdebug then Debug('cyan', 'Last  open: ' .. lastopen) end
  
  if pushMsg > numPushMsg and lastopen ~= devopen then
     pushMsg = 1 ; lastopen = 0
  end 
  if pushMsg > numPushMsg and (os.time() - uxtime) >  pushAgain and pushAgain > 0 then 
     pushMsg = 1 
  end
  fibaro.setTimeout(60000, checkOpenDW)
  end --function

checkOpenDW()
print('Szene gestartet') 

Und hier noch die Variablen Beschreibung: DW-Monitoring-0.2.5.pdf (33,3 KB)