Use water meter to detect big leak and shut off water supply

Posted on
Sun Nov 01, 2015 9:22 am
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Use water meter to detect big leak and shut off water supply

We have all heard of catastrophic house leaks from broken pipes. I have wanted to have a way of detecting a continuous large volume water leak, such as would happen with a broken pipe, and if so then shut off the whole house water valve. After several months of testing, this script and control page seems reliable. Note that my water meter clicks for each tenth of a gallon, so for instance "700" = 70 gallons.

Code: Select all
(*

Concept: Script is launched when the meter detects water beginning to flow and trigger is executed. Script disables the water flow detection trigger so multiple instances are not initiated. It sets initial value to "0" and measures again in 10 seconds, comparing the 10 sec value to the initial value. If 10 sec > initial, it sets variable "WaterHouse_is_Flowing_STILL" to true, which can be monitored on the control page, and allows the detection loop to continue to run. The process continues to loop until either the values are equal, indicating water has stopped, or a user defined maximum volume is exceeded. If exceeded, an action group is executed to initiate water valve shut off. Action group also sends SMS and email to alert user water is off.

The script itself has two parts, one if you want leak detection and max volume, and the other if you are watering the lawn, running bathtub etc, and want the automatic shutoff disabled. Change "WaterHouse_Leak_Script_ENABLED" to false, and it will measure the water but not execute the water shutoff action group.

*)

--start counting water volume:
using terms from application "IndigoServer"
   
   tell application "IndigoServer"
      
      
      --This first section will exectute the water shutoff if enabled by the variable "WaterHouse_Leak_Script_ENABLED" being true.
      
      if value of variable "WaterHouse_Leak_Script_ENABLED" is "true" then
         
         set value of variable "WaterHouse_Leak_Volume" to "0"
         
         set value of variable "WaterHouse_Leak_Script_INHIBITED" to "true" --stops Water Flowing and Leak Script from executing.
         set waterRunningCount_Initial to value of variable "WaterHouse_Leak_Volume"
         set Max_Allowed to value of variable "WaterHouse_is_Flowing_MAX_ALLOWED" as integer
         
         delay 10
         
         set waterRunningCount_10 to value of variable "WaterHouse_Leak_Volume"
         set waterRunningCount_10_Increase to (waterRunningCount_10 - waterRunningCount_Initial)
         
         
         
         if waterRunningCount_10_Increase is greater than "0" then
            log "Water is flowing. Leak Volume and Max allowed are: " & waterRunningCount_10_Increase & ", and " & Max_Allowed
            
            set value of variable "WaterHouse_is_Flowing_STILL" to "true"
            
            repeat while value of variable "WaterHouse_is_Flowing_STILL" is "true"
               set waterRunningCount_Initial to value of variable "WaterHouse_Leak_Volume" as string
               
               delay 10
               set waterRunningCount_10 to value of variable "WaterHouse_Leak_Volume"
               if value of variable "WaterHouse_Leak_Script_LoggingEnabled" is "true" then
                  log "Water is flowing. Leak Volume and Max allowed are: " & waterRunningCount_10 & ", and " & Max_Allowed
               end if
               
               if waterRunningCount_10 is equal to waterRunningCount_Initial then
                  set value of variable "WaterHouse_is_Flowing_STILL" to "false" --stops script
                  set value of variable "WaterHouse_is_Flowing" to "false"
                  set value of variable "WaterHouse_Leak_Script_INHIBITED" to "false" -- this will allow triggers to fire.
                  set waterRunningCount_Initial to "0"
                  log "Water has stopped running. Total volume is " & value of variable "WaterHouse_Leak_Volume"
                  
                  
               end if
               
               
               --This section turns logging on and off so you can see what exactly is happening.
               if value of variable "WaterHouse_Leak_Script_LoggingEnabled" is "true" then
                  log "total measured water use by Water House Max Flow Volume Script is " & value of variable "WaterHouse_Leak_Volume"
               end if
               set WaterHouse_Leak_Volume to value of variable "WaterHouse_Leak_Volume" as integer
               
               
               --This section executes the water shutoff action group if the user-defined maximum volume is exceeded
               if ((WaterHouse_Leak_Volume) as integer) is greater than Max_Allowed then
                  execute group "Water Valve House Close + Circ Pump off Email Sent" --this shuts off house water and sends text. Rename to your action group's name.
                  log "Water House Max Flow Volume Broken Pipe Limit Exceeded -- at least " & Max_Allowed & " tenths of a gallon in one session."
                  set value of variable "WaterHouse_Leak_Script_INHIBITED" to "false"
               end if
            end repeat
            
         end if
         
         
         if waterRunningCount_10 is equal to waterRunningCount_Initial then
            set value of variable "WaterHouse_is_Flowing_STILL" to "false"
            
            set value of variable "WaterHouse_is_Flowing" to "false"
            set waterRunningCount_Initial to "0"
            set value of variable "WaterHouse_Leak_Script_INHIBITED" to "false"
            log "Water has stopped running. Total volume is " & value of variable "WaterHouse_Leak_Volume"
            
         end if
      end if
      
      
      --If "WaterHouse_Leak_Script_ENABLED" is set to "false", this second section just measures water but does not allow the water shutoff to occur.
      if value of variable "WaterHouse_Leak_Script_ENABLED" is "false" then
         
         set value of variable "WaterHouse_Leak_Volume" to "0"
         
         set value of variable "WaterHouse_Leak_Script_INHIBITED" to "true" --stops Water Flowing and Leak Script from executing.
         set waterRunningCount_Initial to value of variable "WaterHouse_Leak_Volume"
         set Max_Allowed to value of variable "WaterHouse_is_Flowing_MAX_ALLOWED" as integer
         --set Max_Allowed to value of variable "WaterHouse_is_Flowing_MAX_ALLOWED" as integer
         --log "Water is flowing. Current Leak Volume and Max allowed are: " & waterRunningCount_10_Increase & ", and " & Max_Allowed
         
         delay 10
         
         set waterRunningCount_10 to value of variable "WaterHouse_Leak_Volume"
         set waterRunningCount_10_Increase to (waterRunningCount_10 - waterRunningCount_Initial)
         
         
         
         if waterRunningCount_10_Increase is greater than "0" then
            log "Water is flowing. Leak Volume and Max allowed are: " & waterRunningCount_10_Increase & ", and " & "NO MAXIMUM. DETECTION TURNED OFF"
            
            
            set value of variable "WaterHouse_is_Flowing_STILL" to "true"
            
            repeat while value of variable "WaterHouse_is_Flowing_STILL" is "true"
               set waterRunningCount_Initial to value of variable "WaterHouse_Leak_Volume" as string
               
               delay 10
               set waterRunningCount_10 to value of variable "WaterHouse_Leak_Volume"
               if value of variable "WaterHouse_Leak_Script_LoggingEnabled" is "true" then
                  log "Water is flowing. Leak Volume and Max allowed are: " & waterRunningCount_10 & ", and " & "NO MAXIMUM. DETECTION TURNED OFF"
               end if
               
               if waterRunningCount_10 is equal to waterRunningCount_Initial then
                  set value of variable "WaterHouse_is_Flowing_STILL" to "false" --stops script
                  set value of variable "WaterHouse_is_Flowing" to "false"
                  set value of variable "WaterHouse_Leak_Script_INHIBITED" to "false" -- this will allow triggers to fire.
                  set waterRunningCount_Initial to "0"
                  log "Water has stopped running. Total volume is " & value of variable "WaterHouse_Leak_Volume"
                  
                  --set value of variable "WaterHouse_Leak_Volume" to "0"
                  
               end if
               
            end repeat
         end if
         
         
         if waterRunningCount_10 is equal to waterRunningCount_Initial then
            set value of variable "WaterHouse_is_Flowing_STILL" to "false"
            
            set value of variable "WaterHouse_is_Flowing" to "false"
            set waterRunningCount_Initial to "0"
            set value of variable "WaterHouse_Leak_Script_INHIBITED" to "false"
            log "Water has stopped running. Total volume is " & value of variable "WaterHouse_Leak_Volume"
            
         end if
      end if
      
   end tell
end using terms from

Last edited by hamw on Sun Nov 01, 2015 11:17 am, edited 5 times in total.

Posted on
Sun Nov 01, 2015 10:00 am
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Re: Use water meter to detect leaks and shut off water suppl

First, your water meter trigger should be incrementing a water usage variable already. This script references "WaterHouse_Leak_Volume" and sets it to "0" once the script begins. This is a cumulative tally, and, during the loop, is referenced to set an "initial"value and then 10 sec later for the comparison value to determine if flow has occurred. It continues counting, and if its value exceeds the user's predefined maximum volume, the water house shut off action group is executed.

The script itself requires two more triggers. The first detects flowing water, in my case via the Phidgets interface, and sets the "WaterHouse_is_Flowing" variable to "true" when the "Phidgets Water Meter" "on/off state" becomes "on". The trigger's condition list only allows it to fire if the variables "WaterHouse_is_Flowing" and "WaterHouse_Leak_Script_INHIBITED" are both false. The former prevents it from constantly firing in and of itself, and the latter checks it from within the script. While it seems "WaterHouse_is_Flowing" is redundant, the slow response rate of the meter - - needs 1/10 gallon, 12.8 oz - - requires this trigger to be inhibited immediately.

The second trigger is called "Water House Fast or Large Volume Leak Detection Script" and is executed when the "WaterHouse_is_Flowing" variable becomes "true". It will only fire if "WaterHouse_Leak_Script_INHIBITED" is "false", to prevent multiple executions of the script. Note that the variable value for "WaterHouse_Leak_Script_INHIBITED" is set from within the script. The action is simply to launch the applescript. I have another condition in this trigger to prevent its execution if, for instance, I am filling the pool.

Here is the control page and variable list (ignore "WaterHouse_Leak_Slow_Detected"). House water flowing icons are RG BiColor 32 PNGs. The left, labeled icon, shows whether water is flowing at all. When the water starts flowing, it fires trigger the "water house is flowing" trigger, whose action sets the variable "WaterHouse_is_Flowing" to "true" and turns the left icon green. The one on the right represents "WaterHouse_is_Flowing_STILL", and it is set to true from within the script if the interval comparison indicates a difference between the time 0 value and time 10 value.

Water Detection Control Page Image.tiff
Water Detection Control Page Image.tiff (35.63 KiB) Viewed 2070 times


Water House Flowing Variable List Image.tiff
Water House Flowing Variable List Image.tiff (38.1 KiB) Viewed 2070 times


Max allowed is the value of the variable "WaterHouse_is_Flowing_MAX_ALLOWED" and is set by control page scripts below. The "max allowed" can be set as a user interface item on the control page, so if you press it you can change the value directly. Otherwise, the arrows, when pressed execute the following control page applescripts to increment the value by "50" up or down. Note that "50" = 5 gallons, as each phidgets pulse represents 1/10th of a gallon.

Code: Select all
using terms from application "IndigoServer"
   tell application "IndigoServer"
      set value of variable "WaterHouse_is_Flowing_MAX_ALLOWED" to ((value of variable "WaterHouse_is_Flowing_MAX_ALLOWED") + 50)
   end tell
end using terms from



and:

using terms from application "IndigoServer"
tell application "IndigoServer"
set value of variable "WaterHouse_is_Flowing_MAX_ALLOWED" to ((value of variable "WaterHouse_is_Flowing_MAX_ALLOWED") - 50)
end tell
end using terms from


Current Flow is the value of "WaterHouse_Leak_Volume"

"Leak Detection ENABLED? ", when pressed, executes "toggle variable: WaterHouse_Leak_Script_LoggingEnabled" and "set variable "WaterHouse_is_Flowing" to false". This last action is needed in case for some reason the script is interrupted and WaterHouse_is_Flowing is stuck on, despite no water flowing. If this is on, the script won't fire. So, if it is stuck, toggle this and it will reset, allowing the trigger to fire.

"Logging ENABLED" simply toggles the variable "WaterHouse_Leak_Script_LoggingEnabled". This will log entries like this if maximum volume is enabled:


Trigger Water House is Flowing
Trigger Water House Fast or Large Volume Leak Detection Script
Script Water is flowing. Leak Volume and Max allowed are: 1, and 650
Script Water is flowing. Leak Volume and Max allowed are: 3, and 650
Script total measured water use by Water House Max Flow Volume Script is 3
Script Water is flowing. Leak Volume and Max allowed are: 4, and 650
Script total measured water use by Water House Max Flow Volume Script is 4
Script Water is flowing. Leak Volume and Max allowed are: 4, and 650
Script Water has stopped running. Total volume is 4
Script total measured water use by Water House Max Flow Volume Script is 4

and this if water shutoff is disabled:

Trigger Water House is Flowing
Trigger Water House Fast or Large Volume Leak Detection Script
Script Water is flowing. Leak Volume and Max allowed are: 1, and NO MAXIMUM. DETECTION TURNED OFF
Script Water is flowing. Leak Volume and Max allowed are: 3, and NO MAXIMUM. DETECTION TURNED OFF
Script Water is flowing. Leak Volume and Max allowed are: 4, and NO MAXIMUM. DETECTION TURNED OFF
Script Water is flowing. Leak Volume and Max allowed are: 5, and NO MAXIMUM. DETECTION TURNED OFF
Script Water is flowing. Leak Volume and Max allowed are: 5, and NO MAXIMUM. DETECTION TURNED OFF
Script Water has stopped running. Total volume is 5


Hope this is useful. Any comments to make it better would be appreciated.
Last edited by hamw on Sun Nov 01, 2015 5:13 pm, edited 1 time in total.

Posted on
Sun Nov 01, 2015 1:11 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Use water meter to detect big leak and shut off water su

hamw wrote:
We have all heard of catastrophic house leaks from broken pipes. I have wanted to have a way of detecting a continuous large volume water leak, such as would happen with a broken pipe, and if so then shut off the whole house water valve. After several months of testing, this script and control page seems reliable. ...
Nice contribution Ham.

Posted on
Thu Nov 05, 2015 9:54 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Re: Use water meter to detect big leak and shut off water su

Thanks very much. I appreciated your input on the concept. :D

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 24 guests