question about timers
Posted: Sunday 05 May 2019 11:03
I have a question about timers.
When a switch is on for x minutes or must be set to off after x minutes, are these timers deleted when the same switch is manually set to off?
I have a switch hetregent which is set for a period of time and if in the period of time a sensor get's a new signal that it is raining the switch hetregent must be set to on for the new/latest period of time and the old period must be deleted.
When a switch is on for x minutes or must be set to off after x minutes, are these timers deleted when the same switch is manually set to off?
I have a switch hetregent which is set for a period of time and if in the period of time a sensor get's a new signal that it is raining the switch hetregent must be set to on for the new/latest period of time and the old period must be deleted.
Code: Select all
return {
on = {devices = {'$tuinwatersensor'}},
logging = {
level = domoticz.LOG_DEBUG , -- Uncomment to override the dzVents global logging setting
marker = "Watermeting"
},
data = {
raintable = { history = true, maxHours = 1 },
},
execute = function(dz, device, info)
local switch = dz.devices('hetregent')
local norm = 5
local DurTimer = 800
local huidwaarde = device.state
local now = os.time(os.date('*t'))
if huidwaarde == nil then -- onderstaande checks moeten na de locals omdat ze deze ook gebruiken!
dz.log("01 Sensor info = Geen waarde opgehaald")
else
dz.data.raintable.add(huidwaarde)
end
local aantal = 0
for i = dz.data.raintable.size,1,-1 do
aantal = aantal +1
item = dz.data.raintable.get(i)
dz.log("00 History data van " .. item.time.rawDate .. " " .. item.time.rawTime ..
" = " .. item.data)
end
dz.log("Deviceinfo---------------------------------------")
dz.log("00 Sensor...........................= " .. device.name)
dz.log("00 Switch-device....................= " .. switch.name)
dz.log("00 Uitzetten.na(in.min).............= " .. DurTimer)
dz.log("Sensor info-------------------------------------")
dz.log("00 Aantal.norm......................= " .. norm)
dz.log("00 Aantal gemeten...................= " .. aantal)
dz.log("00 Aantal.huidige waarde............= " .. huidwaarde)
dz.log("00 Notificatie.switch.laatste update= " .. tostring(switch.lastUpdate.rawTime)) -- deze is goed
dz.log("-------------------------------------------------")
if aantal >= norm then
if switch.state == 'Off' then
switch.switchOn()
switch.switchOff().afterMin(DurTimer)
else
switch.switchOff()
switch.switchOn()
switch.switchOff().afterMin(DurTimer)
end
dz.log('Script: ' .. info.scriptName .. ' Regendruppel signalen (' .. aantal .. ') is gelijk of boven de norm(' .. norm .. '), ' .. switch.name .. ' wordt geactiveerd voor ' .. tostring(DurTimer) .. ' Minuten ', dz.LOG_INFO)
end
end
}