Notes from Sand Hill


Logo

XTension Tech Notes

Sandhill Crane


ID: TN.WaterPump
Subject: A simple switch gives a lot of information.
Date:4/25/97
Applicability:All versions of XTension after 1.5
Contributor:Michael


A simple system:
a switch which signifies on or off
a way of signaling the state of the switch to a computer
a clock which gives a way of measuring elapsed time
( for example: a switch that detects the on/off of a water well pump )

All you do is connect wires from the keyboard switch to a PowerFlash module.
This is nothing more than a simple 'plunger type' switch which is pushed and released by the action of the pressure switch on this common installation. I used just an old switch taken from a computer keyboard.

pump monitor

With only these data, you can derrive a good deal of useful information:

verification of operation - if you know that it should turn on/off within limits
duty cycle - how hard is the device working?
duty cycle trend - is it working harder over time?
failure prediction - trends in some devices indicate that maintenance is required.
failure detection - is it working 'too' hard?
output - how much is it doing of what it does?
history - how much did it do yesterday? Last month?
cost - how much does it cost to run this device?

In addition, you can use the status of this device to modify the behavior of other devices. For example, if the pump is 'misbehaving', you might not want to turn on the sprinkler system, and you might want to disable the hot water heater. Of course you would want also to annunciate this condition.

Although this missal describes the monitoring of a water well pump, I believe that there are many similar devices in your world which would yield as much information and usefulness. ( like pool/spa pumps and filters ? )

The setup for the switch in the case of the water pump was to position a switch in such a way as to sense the physical movement of the pressure switch armature. Thus each time the pump turns on, the switch closes, and by connection to a X-10 PowerFlash module, sends a X-10 message to XTension signifying on or off.

I should also point out that the switch connection can be monitored by one of the discrete inputs of a ADB I/O, and with the aid of a script applet can stimulate XTension in the same way that X-10 commands do.

Note that it may be required that you mount the switch so that it is depressed (or ON) when the pump is OFF. XTension covers this case by offering the 'Use reverse logic' option in the unit setup dialog. This allows you to write scripts which assume 'positive logic', where an ON really means an ON...

Set up the database:

The setup for XTension is just as simple. You need to create several new units. Only one of the units is a 'real' unit with a X-10 address. All the rest are what we call 'pseudo' units, used as counters, accumulators and indicators. These have no address, and are declared to be 'dimmable'. Each of these are described more carefully below.

Once you have created the new units, you can test the system without actually having the 'switch' installed. Just manually turn the unit on or off with the control panel in XTension. Watch the behavior of the scripts as represented by the changing values of the 'pseudo' units.

About the scripts:

After the units are in the database, you need to create a on/off script pair for the real 'switch'. In the example, we call this "thePump". Then you need to create a few global scripts and some scheduled events.

The on and off scripts for "thePump" are really the workhorse of the pump monitor system. With these, we can tally the total number of events on and off for the pump.

With knowledge of the passage of time we can measure the length of time the pump was on and off. By dividing the total number of seconds on by the number of seconds off for the same period, we can get a measure of the 'duty cycle' of the pump.

By keeping track of the past values of the duty cycle, we can get an idea of the 'reasonableness' of the pump activity and thus beware of unusual activity. In the case of the water pump, it is useful to detect when the pump is turning on/off too frequently (the duty cycle gets too high). This may mean that there is a big leak, or that the pump has 'lost its head' and needs to be drained and re-pressurized.

About gallons of water:

Not only is it useful to detect this potential failure, but it is also interesting to know just how much the pump does work in an hour or day or month. How much water does it pump?

Turn off all of the outputs from the pump except for a single garden hose with a valve on the end.

Turn on the hose until the pump turns on.
WAIT until the pump turns off again.

Then into a 5 gallon bucket, measure the amount of water pumped until the pump turns on again. Repeat this procedure at least three times. The results should be very consistent. My pump for example takes 45 seconds to pump 15 gallons.

Then, from the times logged by XTension, divide the amount of water by the number of seconds the pump was on. ( average over the 3 trials )
This is a reasonable measure of the amount of water that your pump pumps each second. Unless you have a very large pump, this is probably less than one gallon per second.

So, if we measure the number of seconds that the pump is on, multiply that by the gallons/second value, and we have a reasonable total for the volume of water pumped in any period.

Making history :

By maintaining several counters and resetting each at a given interval, we can create counters representing usage for the hour, day, week etc.

We need some scheduled events to maintain the time-based counters. For example, the "pumpHourly" script will reset certain 'hourly' variables (pseudos), and calculate averages etc. The same goes for daily, weekly, monthly and yearly events.

More about these scheduled events below.

A bit about philosophy :

This system certainly should not be expected to yield an precise measure of water usage, but it can be usefully accurate.

There are also likely to be 'holes' in this logic such as the possibility that multiple on/off events are missed, this logic would yield only one count of a missed on or off.

The accumulators for water assume that usage for any day does not exceed 32000 gallons. Weekly totals and thereafter are scaled by 10 and 1000. You may want or need to accumulate or monitor greater or lesser increments.

The new database units :

Following is a description of the database units that you need to create for this example:

thePump -- this is the only 'real' unit in this whole example. It represents the real switch you install on your pump. It must be assigned a specific X-10 address. It cannot be 'dimmable', but you may need to set the 'use reverse logic' option according to the logic of your 'switch'.

All of the following units must be created as 'No address', and 'Dimmable'.
Add the descriptions as written here :

PavgDuty -- Running average duty cycle of the pump. Represented as a ratio of PdayOn divided by PdayOff.

PhourOn -- Hourly accumulation of seconds the pump was on.

PhourOff -- Hourly accumulation of seconds the pump was off.

PavgOn -- Running daily average of the number of seconds that the pump was on.

PavgOff -- Running daily average of the number of seconds that the pump was off.

PtimesOn -- Number of times pump turned on this day.

PtimesOff -- Number of times pump turned off this day.

PdayOn -- Number of 1/10's of minutes that the pump was on this day.

PdayOff -- Number of 1/10's of minutes that the pump was off this day.

PminOn -- Minimum number of seconds that the pump has been observed on.

PminOff --Minimum number of seconds that the pump has been observed off.

PmaxOn -- Maximum number of seconds that the pump has been observed on.

PmaxOff -- Maximum number of seconds that the pump has been observed off.

PMissedOn -- Number of times the pump ON has been missed. (just info)

PMissedOff -- Number of times the pump OFF has been missed. (just info)

PWaterDay -- Number of gallons of water pumped this day.

PWaterWeek -- Tens of gallons of water pumped this week.

PWaterMonth -- Tens of gallons of water pumped this month.

PWaterYear -- Thousands of gallons of water pumped this year.

PWater1 -- Number of gallons of water pumped yesterday.

PWater2 -- Number of gallons of water pumped two days ago.

PWater3 -- Number of gallons of water pumped three days ago.

PWlastMonth-- Number of gallons of water pumped last month.

PWmonth2-- Number of gallons of water pumped two months ago.

PWmonth3-- Number of gallons of water pumped three months ago.

Pduty1 -- Average duty cycle yesterday

Pduty2 -- Average duty cycle two days ago

Pduty3 -- Average duty cycle three days ago



Here are the scripts: ( you can copy/paste them )

The ON script for the water pump sensor :
The ON script runs each time the pump turns on and accumulates information about the period that the pump was OFF. The OFF script does the same for the period that the pump was ON.

--This is the ON script for the water pump
-- Here we maintain statistics for the pump and water usage
-- Make sure that we didn't miss an OFF event.

write log "Pump on"
set value of "PtimesOn" to (value of "PtimesOn") + 1

if (status of "thePump") is false then
	set secsOff to time delta of "thePump"
else
	--we missed the last off...
	write log "Missed pump off event, assuming average."
	set value of "PtimesOff" to (value of "PtimesOff") + 1
	set value of "PMissedOff" to (value of "PMissedOff") + 1
	
	--If we're going to fudge for the missed event, we have to
	-- fudge the water totals also.
	set pWater to (value of "PavgOn") / 3
	set value of "PWaterHour" to ((value of "PWaterHour") + pWater)
	set value of "PWaterDay" to ((value of "PWaterDay") + pWater)
	
	set secsOff to value of "PavgOff"
end if

--Now continue with the stats.  Here we're going to need tenths of minutes.
set tenthsOff to secsOff / 6
set value of "PhourOff" to ((value of "PhourOff") + secsOff)
set value of "PdayOff" to ((value of "PdayOff") + tenthsOff)

--ignore averaging at 'initial' conditions
if (value of "PdayOn") ­ 0 then
    set value of "PavgDuty" to (((value of "PdayOn") / (value of "PdayOff")) * 100)
end if

set value of "PavgOff" to (((value of "PdayOff") * 6) / (value of "PtimesOff"))

if (value of "PmaxOff") < secsOff then
	set value of "PmaxOff" to secsOff
end if
if (value of "PminOff") > secsOff then
	set value of "PminOff" to secsOff
end if
--END of the ON script for thePump


The OFF script for the water pump sensor :

The OFF script runs each time the pump turns on and accumulates information about the period that the pump was ON. The ON script does the same for the period that the pump was OFF.

--This is the OFF script for thePump
--This script measures the time that the pump was ON
-- and updates some of the usage counters.
-- Make sure that we didn't miss an ON event...

write log "Pump off"
set value of "PtimesOff" to (value of "PtimesOff") + 1

if (status of "thePump") is true then
	set secsOn to time delta of "thePump"
else
	--we missed the last on...assume average
	write log "Missed pump on event"
	set value of "PtimesOn" to (value of "PtimesOn") + 1
	set value of "PMissedOn" to (value of "PMissedOn") + 1
	set secsOn to value of "PavgOn"
end if

set tenthsOn to secsOn / 6
set value of "PhourOn" to ((value of "PhourOn") + secsOn)
set value of "PdayOn" to ((value of "PdayOn") + tenthsOn)

set value of "PavgOn" to (((value of "PdayOn") * 6) / (value of "PtimesOn"))

if (value of "PmaxOn") < secsOn then
	set value of "PmaxOn" to secsOn
end if
if (value of "PminOn") > secsOn then
	set value of "PminOn" to secsOn
end if

--now for the water usage calcs...mine is 3.0 seconds/gallon...
set pWater to secsOn / 3
set value of "PWaterHour" to ((value of "PWaterHour") + pWater)
set value of "PWaterDay" to ((value of "PWaterDay") + pWater)
--END of OFF script for thePump


The scheduled scripts :

The following scripts are all 'Global' scripts, and can be copy/pasted into the edit script dialog :

PumpHourly --
--this script takes care of rolling over the
--counters for the water pump usage system
-- it should run hourly...

turnoff "PhourOn"
turnoff "PhourOff"
turnoff "PWaterHour"
--end PumpHourly script


Daily Tasks --

-- This script should do all daily tasks.
--  Notice that you might have one single script which runs daily and
--  resets or accumulates certain items in your database.
--  This example shows only elements relating to 'thePump'

-- maintain history for past 3 days of the pump duty cycle
set value of "Pduty3" to value of "Pduty2"
set value of "Pduty2" to value of "Pduty1"
set value of "Pduty1" to value of "PavgDuty"

-- reset some of the daily counters
turnoff "PdayOn"
turnoff "PdayOff"
turnoff "PtimesOn"
turnoff "PtimesOff"

-- maintain the weekly, monthly and yearly totals :
set pDay to value of "PWaterDay" / 10
set value of "PWaterWeek" to ((value of "PWaterWeek") + pDay)
set value of "PWaterMonth" to ((value of "PWaterMonth") + pDay)
set value of "PWaterYear" to ((value of "PWaterYear") + (pDay/100))

-- maintain history of water usage for the past 3 days
set value of "PWater3" to value of "PWater2"
set value of "PWater2" to value of "PWater1"
set value of "PWater1" to value of "PWaterDay"
turnoff "PWaterDay"
--end Daily Tasks


Weekly Tasks --

--This script takes care of weekly tasks

turnoff "Weekly Rainfall"
turnoff "PweekOn"
turnoff "PweekOff"
turnoff "PWaterWeek"
--end of Weekly Tasks


Monthly Tasks --

--This script handles monthly things

turnoff "Monthly Rainfall"
turnoff "PmonthOn"
turnoff "PmonthOff"
set value of "PWMonth3" to value of "PWMonth2"
set value of "PWMonth2" to value of "PWlastMonth"
set value of "PWlastMonth" to value of "PWaterMonth"
turnoff "PWaterMonth"
write log "Monthly system cleanup"
--end of Monthly Tasks


Yearly Tasks --

--  this script should be executed manually each year or on demand
--  are there other things that you want to do yearly? 

turnoff "PWaterYear"


Conclusion:

Although this looks like a lot of bother, it is intended to show how much information can be gleaned from the simple transitions of a switch.

After working with the example, you may want to limit the number of items that you maintain.

On the other hand, there are some items missing from the scripts such as detection and notification of an undesirable trend. You will want to add your own, with logic that is reasonable for your system.

You should also create a new 'List' and include all of these new units in it so that you can easily observe just the elements of the water pump system.

Don't forget that you can simulate this whole thing by just turning 'thePump' on and off manually from the control panel. When you're ready to set it running for real, just reset all of the accumulators.

If you're really worried about a particular device, you might want to schedule another script at the end ofeach on or off script. This script would be scheduled for a time which is two times longer than the average for the on or off. If this script runs and finds that the device has not turned on or off in a reasonable time, you could annunciate it or modify your counters accordingly.



Additional help is available on our website: www.shed.com
Or directly to Michael Ferguson at: 407-349-5960
Or mail to Sand Hill Engineering Inc. Box 517 Geneva FL 32732
All icons, graphics and text copyright ¨1999 Sand Hill Engineering Inc.