Code: Select all
return {
on = {
devices = { 'Watertest' }
},
data = {
lastValue = { initial = 0 },
lastTime = { initial = os.time() }
},
execute = function(domoticz, device)
local currentValue = device.counter
local currentTime = os.time()
local deltaLiters = currentValue - domoticz.data.lastValue
local deltaTime = (currentTime - domoticz.data.lastTime) / 60
domoticz.log(string.format("ΔL: %.2f, Δt: %.2f min", deltaLiters, deltaTime))
if deltaLiters >= 0 and deltaTime > 0 then
local flow = deltaLiters / deltaTime
flow = math.floor(flow * 1000)
domoticz.log('Obliczony przepływ: ' .. flow .. ' L/min')
local czujnik = domoticz.devices('Flow')
if czujnik then
czujnik.updateWaterflow(flow)
else
domoticz.log("Nie znaleziono urządzenia 'Przepływ'", domoticz.LOG_ERROR)
end
end
domoticz.data.lastValue = currentValue
domoticz.data.lastTime = currentTime
end
}