Code: Select all
-- *** user settings below this line **
local doorSensorName1 = 'ATS1' -- change to the name of your doorSensor'
local doorSensorName2 = 'ATS2' -- change to the name of your doorSensor'
local scriptVar = 'simpleDelayedNotification'
local secondsUntilNotification = 5
-- *** No changes required below this line **
return
{
on = {
devices = { doorSensorName1, doorSensorName2 },
httpResponses = { scriptVar },
},
execute = function(domoticz, item)
local doorSensor1 = domoticz.devices(doorSensorName1)
local doorSensor2 = domoticz.devices(doorSensorName2)
local function retriggerScript(delay)
local url = domoticz.settings['Domoticz url'] ..
'/json.htm?type=command¶m=addlogmessage&message=' ..
scriptVar .. '%20retriggered'
domoticz.openURL ({ url = url, callback = scriptVar }).afterSec(delay) -- to come back after delay seconds
end
if item.isDevice and item.active then
retriggerScript(secondsUntilNotification) -- come back after x seconds
else -- triggered by HTTPResponse
if (item == doorSensor1 and doorSensor1.active) then
local secondsOpened = doorSensor1.lastUpdate.secondsAgo
if secondsOpened >= secondsUntilNotification then
domoticz.notify(doorSensorName1,'Still open after ' .. secondsOpened .. ' seconds.' )
end
elseif (item == doorSensor2 and doorSensor2.active) then
local secondsOpened = doorSensor2.lastUpdate.secondsAgo
if secondsOpened >= secondsUntilNotification then
domoticz.notify(doorSensorName2,'Still open after ' .. secondsOpened .. ' seconds.' )
end
end
end
end
}
Code: Select all
-- *** user settings below this line **
local doorSensorName1 = 'ATS1' -- change to the name of your doorSensor'
local doorSensorName2 = 'ATS2' -- change to the name of your doorSensor'
local scriptVar = 'simpleDelayedNotification'
local secondsUntilNotification = 5
-- *** No changes required below this line **
return
{
on = {
devices = { doorSensorName1, doorSensorName2 },
httpResponses = { scriptVar },
},
execute = function(domoticz, item)
local doorSensor1 = domoticz.devices(doorSensorName1)
local doorSensor2 = domoticz.devices(doorSensorName2)
local function retriggerScript(delay)
local url = domoticz.settings['Domoticz url'] ..
'/json.htm?type=command¶m=addlogmessage&message=' ..
scriptVar .. '%20retriggered'
domoticz.openURL ({ url = url, callback = scriptVar }).afterSec(delay) -- to come back after delay seconds
end
if item == doorSensor1 then
if item.isDevice and item.active then
retriggerScript(secondsUntilNotification) -- come back after x seconds
else -- triggered by HTTPResponse
if doorSensor1.active then
local secondsOpened = doorSensor1.lastUpdate.secondsAgo
if secondsOpened >= secondsUntilNotification then
domoticz.notify(doorSensorName1,'Still open after ' .. secondsOpened .. ' seconds.' )
end
end
end
elseif item == doorSensor2 then
if item.isDevice and item.active then
retriggerScript(secondsUntilNotification) -- come back after x seconds
else -- triggered by HTTPResponse
if doorSensor2.active then
local secondsOpened = doorSensor2.lastUpdate.secondsAgo
if secondsOpened >= secondsUntilNotification then
domoticz.notify(doorSensorName2,'Still open after ' .. secondsOpened .. ' seconds.' )
end
end
end
end
end
}