jmleglise wrote:To help you, this is a code (for another purpose) that can inspire you.
Thank you jmleglise. I have modified the code a bit, the result is below.
The trigger is 'time based', so it runs every minute. To prevent a mail bomb it only checks once a day, at 17:00 hrs.
It would be better if the table was expended with a third index ('Sensorstate OK / NOK) and that the table was stored in a user variable. That would give the possibility to direct (and only) send messages when the sensor changes it's status (connection lost / connection restored).
I don't know how to store and read the table values (yet), so To Be Continued
Code: Select all
-- Checks if some sensors have been received recently, and
-- 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
index=1
now = os.time()
local tableDeviceToCheck = { -- timeout for each device, in seconde.
["badkamer thermo hygro sensor"]=3600, -- 1 uur
["Weerstation"]=14400, -- 4 uur
}
commandArray={}
date = os.date("*t")
if date.hour==17 and date.min==0 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.. ' seconden geen reactie, grenswaarde ='..deviceTimeOut)
-- If not seen since timeout, send an email
if (lastAlive + deviceTimeOut) < now then
commandArray[index]={['SendNotification']='Melding#Device '..deviceName..' is niet gezien sinds '..s..' seconden. Batterij leeg?#0'}
index = index + 1
end
end
end
return commandArray