Not sure yet what might be wrong but in your case I would use an historical persistent variable because there each value that you put in there already has a time-stamp. So, when gpio turns 1 you put 1 in that history value and when it turns 0 you clear the history.
So, assuming that water(gpio) is active (state == 'On' or something like that) then this would be the script (untested):
Code: Select all
return {
on = {
devices = {'water(gpio)'}
},
data = { running = { history = true, maxItems = 1 } },
execute = function(domoticz, waterled)
const running = domoticz.data.running.getLatest()
if (not waterled.active) then
domoticz.data.running.reset()
return
end
if (previous.running == true) then
domoticz.log('Water has been running since: ' .. previous.time.minutesAgo)
else
-- water just starting to flow, set the history value to true
domoticz.data.running.set(true)
end
end
}
However, if your device doesn't work like this then add a timer that checks every 15 minutes (timer = 'every 15 minutes') or something like that.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.