-
Notifications
You must be signed in to change notification settings - Fork 3
/
deadsensors.lua
49 lines (37 loc) · 1.59 KB
/
deadsensors.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- otherwise sends a notification to tell us to go check the lost one.
-- https://www.domoticz.com/forum/viewtopic.php?f=15&t=9711&p=112074#p112074
-- 1 hour = 3600 seconds
-- 1 day = 86400
-- 7 days = 604800
index=1
now = os.time()
print("[Check_Sensor_Battery] Checking for last sensor updates")
local tableDeviceToCheck = { -- timeout for each device, in seconde.
["Congélateur"]=172800, -- 2 days
["Salle de bain"]=172800, -- 2 days
["Cuisine"]=172800, -- 2 days
["Frigo"]=172800, -- 2 days
}
commandArray={}
date = os.date("*t")
if date.hour==18 and date.min==30 then
for deviceName, deviceTimeOut in pairs(tableDeviceToCheck) do
s = otherdevices_lastupdate[deviceName]
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
lastAlive = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
tijd = now - lastAlive
print(deviceName .." "..tijd.. ' secondes sans réponse, valeur limite ='..deviceTimeOut)
-- If not seen since timeout, send an email
if (lastAlive + deviceTimeOut) < now then
commandArray[index]={['SendNotification']='Le Device '..deviceName..' ne répond plus depuis '..s..' secondes. Batterie vide?'}
print("[Check_Sensor_Battery] Sending alert for device "..deviceName..' not seen for '..s..' seconds. Batery maybe down.')
index = index + 1
end
end
end
return commandArray