local scriptVar = 'lastSeen'
return {
on = { timer = {'every 30 minutes'}, httpResponses = { scriptVar }},
--on = { timer = {'every minute'}, httpResponses = { scriptVar }}, -- Only use this one to test. When working disable it and activate "every 30 minutes"
--on = { timer = {'at 08:00', 'at 10:00'}, httpResponses = { scriptVar }},
logging = { level = domoticz.LOG_ERROR, marker = scriptVar },
data = { notified = { initial = {} } },
execute = function(dz, item)
--Telegram settings
local telegram = true -- Set true for sending telegram, set false for NOT sending telegram.
--Email settings (domoticz email settings have to be filled in)
local email = false -- Set true for sending email, set false for NOT sending email.
local mailaddress = '
[email protected]' -- Fill in your e-mail address, which the notification needs to be send to.
-- Global settings
local notifyTime = 'at 01:00, at 03:00, at 05:00, at 07:00, at 09:00, at 11:00, at 13:00, at 15:00, at 17:00, at 19:00, at 21:00, at 23:00' -- You can add multiple notification times, i.e. 'at 12:00, at 20:00'
local notifyHead = 'dzCheckSensors' -- This is the start of everynotification, so you know it is this script.
-- Devices to check NO holiday.
-- Devices name or IDX number column = Time column in seconds
local devices_No = {
['Temp-1 (buiten)'] = 43200, -- 12 Hours
['Temp-2 (zolder)'] = 43200, -- 12 Hours
['Temp-3 (douche)'] = 43200, -- 12 Hours
['Temp-4 (meterkast)'] = 43200, -- 12 Hours
['Temp-5 (TVkast L)'] = 43200, -- 12 Hours
['Temp-6 (TVkast R)'] = 43200, -- 12 Hours
['Temp-7 (schuur)'] = 43200, -- 12 Hours
['Temp-8 (keuken)'] = 43200, -- 12 Hours
['Temp-9 (huiskamer)'] = 43200, -- 12 Hours
['Temp-10 (kelder)'] = 43200, -- 12 Hours
['Temp 11 (kruipruimte)'] = 86400, -- 24 Hours
['Temp-12 (CV switch)'] = 43200, -- 12 Hours
['Temp-13 (WC)'] = 43200, -- 12 Hours
['Temp-14 (display)'] = 43200, -- 12 Hours
['Temp-16 koelkast kk)'] = 43200, -- 12 Hours
['Temp-15 (diepvries bkk)'] = 43200, -- 12 Hours
['Temp-17 (veranda)'] = 43200, -- 12 Hours
['Brandmelder (schuur)'] = 43200, -- 12 Hours
['Brandmelder (bijkeuken)'] = 43200, -- 12 Hours
['Brandmelder (keuken)'] = 43200, -- 12 Hours
['Brandmelder (overloop)'] = 43200, -- 12 Hours
['Brandmelder (meterkast)'] = 43200, -- 12 Hours
['Brandmelder (zolder)'] = 43200, -- 12 Hours
['Brandmelder (huiskamer)'] = 43200, -- 12 Hours
['Brandmelder (reserve)'] = 43200, -- 12 Hours
['Waterteller'] = 43200, -- 12 Hours
['Smart plug (WC)'] = 43200, -- 12 Hours
['Smart plug (airco)'] = 3600, -- 1 Hours
['Smart plug (bkk groep)'] = 300, -- 5 Minutes
['Smart plug (huiskamerverlichting rechts)']= 3600, -- 1 Hours
['Buitenverlichting (schutting)'] = 43200, -- 12 Hours
['Veranda verlichting)'] = 43200, -- 12 Hours
['Smart plug (boiler)'] = 43200, -- 12 Hours
['Smart switch (verwarming veranda)'] = 86400, -- 24 Hours
['DWS (schuur)'] = 43200, -- 12 Hours
['DWS (Sonoff)'] = 43200, -- 12 Hours
['DWS (poort voor)'] = 43200, -- 12 Hours
['DWS (poort achter)'] = 43200, -- 12 Hours
['DWS (huiskamer raam)'] = 43200, -- 12 Hours
['Bewegingssensor (zolder)'] = 86400, -- 24 Hours
['Bewegingssensor (schuur)'] = 43200, -- 12 Hours
['Deurbel'] = 43200, -- 12 Hours
['Veranda verwarming aan/uit'] = 43200, -- 12 Hours
['Dakgootsensor (schuur)'] = 604800, -- 1 Week
['Thermostaat CV switch (AAN = boven)'] = 43200, -- 12 Hours
['Radiator (SLK1)'] = 3600, -- 1 Hours
['Radiator (SLK2)'] = 3600, -- 1 Hours
['Radiator (SLK3)'] = 3600, -- 1 Hours
['Radiator (BKK)'] = 3600, -- 1 Hours
['Radiator (gang)'] = 3600, -- 1 Hours
['Gas)'] = 3600, -- 1 Hours
}
-- Devices to check when it is holiday.
-- Devices name or IDX number column = Time column in seconds
local devices_Yes = {
['Temp-1 (buiten)'] = 1209600, -- 14 Days
['Bewegingssensor (schuur'] = 1209600, -- 14 Days IDX335=Dashboard-webpage-check
}
-- Don't change things undernead this line
local notified = dz.data.notified -- short reference
function Timers(sec)
local ti
sec=tonumber(sec)
if sec == nil then ti='NIL'
elseif sec >= 86400 then ti=string.sub(tostring(sec/24/3600),1,4)..' days'
elseif sec >= 3600 then ti=string.sub(tostring(sec/3600),1,4)..' hours'
elseif sec >= 60 then ti=string.sub(tostring(sec/60),1,4)..' minutes'
else ti=sec..' seconds'
end
return ti
end
if not (item.isHTTPResponse) then
dz.openURL({
url = dz.settings['Domoticz url'] .. '/json.htm?type=devices&used=true',
callback = scriptVar })
else
if dz.devices('opVakantie').state== 'On' then
dz.log(notifyHead .." ".. 'Vakantie-On',dz.LOG_FORCE)
DevicesToCheck = devices_Yes
else
dz.log(notifyHead .." ".. 'Vakantie-Off',dz.LOG_FORCE)
DevicesToCheck = devices_No
end
local Time = require('Time')
for _, node in pairs(item.json.result) do
local toCheck = ( DevicesToCheck[node.idx] or DevicesToCheck[node.Name])
if toCheck then
local lastUpdate = Time(node.LastUpdate).secondsAgo
local deviceName = (node.Name or node.idx)
local threshold = toCheck
if lastUpdate < threshold then
--device is alive
if notified[deviceName] == nil then
dz.log(notifyHead .." "..deviceName.." : "..Timers(lastUpdate).. ' was last response, threshold='..Timers(threshold),dz.LOG_FORCE)
else
dz.log(notifyHead .." ".. ' Signal back from sensor '..deviceName,dz.LOG_FORCE)
notified[deviceName] = nil --remove from notified list
if telegram then
dz.notify(notifyHead, notifyHead .." ".. 'Signal back from sensor '..deviceName..'.',dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz device check', ''..notifyHead.. ' Signal back from sensor '..deviceName..'', ''..mailaddress..'')
end
end
else
--lost signal:
if notified[deviceName] == nil then
dz.log (notifyHead .." ".. 'Signal lost: '..deviceName .." sent "..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?',dz.LOG_FORCE)
notified[deviceName] = 1
if telegram then
dz.notify(notifyHead, notifyHead ..' Signal lost: '..deviceName ..' sent '..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?',dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz device check', ''..notifyHead..' Signal lost: '..deviceName ..' sent '..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?', ''..mailaddress..'')
end
elseif
dz.time.matchesRule(notifyTime) and
dz.devices('opVakantie').state == 'Off'
then
dz.log(notifyHead .." ".. 'Reminder, '..deviceName .." sent "..Timers(lastUpdate).. ' the last signal. Battery empty?',dz.LOG_FORCE)
if telegram then
dz.notify(notifyHead, notifyHead .." ".. 'Reminder, '..deviceName .." sent "..Timers(lastUpdate).. ' the last signal. Battery empty?',dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz device check', ''..notifyHead..' Signal lost: '..deviceName ..' sent '..Timers(lastUpdate).. ' the last signal, threshold='..Timers(threshold)..'. Battery empty?', ''..mailaddress..'')
end
end
end
end
end
end
end
}