Water Usage & Leak Monitor
This script monitors water flow and leakage, updating the status on AWTRIX3. It calculates the percentage of time water is flowing and checks for continuous micro-leaks (e.g., dripping).
Is this your flow?
If you created this flow, open your saved edit link to add it to your account. You can then manage it whenever you sign in. Adding it to your account replaces the edit link.
🚀 Flow:
-
Trigger:
- Executes every 1 minute to analyze water flow and leakage data.
-
Condition:
- Monitors the water flow from "Watermeter - Current usage".
- Tracks the time:
- With flow (leakage detection).
- Without flow (to detect extended periods of no activity).
-
Actions:
✅ If flow > 0:- Resets the "no flow" timer.
- Increases the percentage time with flow, up to a maximum of 100%.
🛑 If flow = 0:
- Tracks time with no flow.
- Checks for periods of 2 hours with no flow to reset micro-leak tracking.
⚠️ Leak Detection:
- If no 2-hour flowless period is detected within 24 hours, sets leakage to 100%.
-
AWTRIX3 Updates:
- Sends real-time water flow (liters/min) and leakage percentage to AWTRIX3 via the "AWTRIX3 - Send Custom App" device.
-
Logging:
- Provides detailed logs of flow status, time with/without flow, and leakage percentage.
More information:
Domoticz:
www.domoticz.com
Domoticz AWTRIX3 Plugin:
https://github.com/galadril/Domoticz-AWTRIX3-Plugin
KXydoDKPApjL.json
local FLOW_DEVICE = 'Watermeter - Current usage' -- Flow device
local LEAK_DEVICE = 'Watermeter - Leakage percent' -- Percent dummy device
return {
active = true,
-- Trigger section: run the script every 1 minute
on = {
timer = {
'every 1 minutes'
}
},
-- Custom logging level for this script
logging = {
level = domoticz.LOG_INFO,
marker = "AWTRIX_LEAK"
},
data = {
time_0_flow = { initial = 0 },
total_time = { initial = 0 },
currentIndex = { initial = 0 }
},
execute = function(domoticz)
-- Flow in liters/minute
local flow = tonumber(domoticz.devices(FLOW_DEVICE).rawData[1])
-- Dummy device in %
local leakage = domoticz.devices(LEAK_DEVICE)
local time_with_flow = tonumber(leakage.rawData[1])
local new_time_with_flow = time_with_flow
-- 1 / Leakage "open valve"
if (flow > 0) then
domoticz.data.time_0_flow = 0 -- There is flow
new_time_with_flow = new_time_with_flow + 1 -- Time with flow
if (new_time_with_flow > 100) then
new_time_with_flow = 100
end
else
new_time_with_flow = 0
domoticz.data.time_0_flow = domoticz.data.time_0_flow + 1 -- Time without flow
end
-- 2 / Micro continuous flow (drip)
domoticz.data.total_time = domoticz.data.total_time + 1 -- Time without since last 2 hours with no flow
if (domoticz.data.time_0_flow > 120) then
-- 2 hours with no flow
domoticz.data.total_time = 0
elseif (domoticz.data.total_time > (60 * 24)) then
-- 24 hours since last 2 hours with no flow
new_time_with_flow = 100
end
-- Log
domoticz.log(new_time_with_flow .. ' minutes with flow')
domoticz.log(domoticz.data.time_0_flow .. ' minutes without flow')
domoticz.log(domoticz.data.total_time .. ' minutes without 2hrs without flow')
-- Update dummy device %
if (time_with_flow ~= new_time_with_flow) then
leakage.update(0, new_time_with_flow)
end
-- Description for AWTRIX3
local flowStatus = string.format("%.1f L/min", flow)
local leakStatus = string.format("%d%%", new_time_with_flow)
-- Create individual JSON entries for flow and leak
local statuses = {
{ app = 'Water1', text = flowStatus, icon = 18191 }, -- Flow status with its icon
{ app = 'Water2', text = leakStatus, icon = 59365 } -- Leak status with its icon
}
-- Send to AWTRIX3
local appDevice = domoticz.devices('AWTRIX3 - Send Custom App')
if appDevice then
local statusesJSON = domoticz.utils.toJSON(statuses)
domoticz.log("Sending data to AWTRIX: " .. statusesJSON, domoticz.LOG_INFO)
appDevice.setDescription(statusesJSON)
appDevice.switchOn().afterSec(2)
else
domoticz.log("AWTRIX3 - Send Custom App device not found", domoticz.LOG_ERROR)
end
end
}