Raspberry pi water logger: Time stamp events from a physical water meter installed in my main house supply line. Display the resulting timestamp data in fun ways.
- raspberry pi single board computer (any model)
- in-line water meter with a reed switch output such as SPWM-075 from EKM Metering
- a plumber to install the water meter (or DYI)
- misc wires to connect the water meter to the pi
- wet : a shell script to install wet.py as a daemon so that it automatically runs at power-up.
- wet.py : appends a timestamp to waterlog.txt on each event (open-close or close-open)
- waterlog.txt : file generated by wet.py and read by wetbin.py
- wetbin.py : basic routines to retrieve waterlog.txt and collate the timestamps into a python list
- wetui.py : display a table of gallons used over a set of time intervals
- wetgraph.py : plot the water rates over time (requires graphics on the client)
- With the permanent drought in California, I wanted to see exactly how much water my house uses and on what.
- It seemed like an easy project for a raspberry pi.
- Money (plus tax and shipping):
- $70 for the SPWM-075 from EKM
- $90 Raspberry pi 3 starter. more than you need for this project but less trouble than buying all the parts individually.
- $7 optional stuff to solder it togetther instead of plug board (assumes you have a soldering iron):
- $5 PCB breadboard
- $2 IDC breakout header for the PCB breadboard
- $150 to hire a plumber to install the water meter? I don't really know. I have all the tools because I replumbed my entire house a few years ago. YMMV.
- Time (depends a great deal on your experience with the pi, Linux, etc)
- 2 weeks waiting for UPS to deliver the parts
- an afternoon to install the SPWM-075 into the main supply line. May include one or more trips to the hardware store for the parts that you thought you had but can't find in all the junk in your basement/garage/attic.
- an evening to install python on your windows computer
(Wow. This adds up to more than I thought. But, if you already have a pi, are able to plumb your own pipes, and have a bunch of the parts from other projects (like me), then it's only $70 for the EKM water meter.)
The San Jose Water Company meter is out at the street. I could have tried opening it up, gluing a magnet on the fastest dial, and gluing a reed switch on the outside, but I'm guessing SJWC would not like that. So it seemed less trouble and more reliable to install my own meter in the main supply line.
Not very complicated: There's a 40 pin connector on the pi with General Purpose Input Output (GPIO). I only needed the first 10 pins so that's all I show in the schematic below. The pi starter kit has a 40 pin cable. Be sure to plug it in properly (pin 1 to pin 1).
-
Pin 1 from the pi supplies 3.3 volts to this circuit.
-
Pin 9 is the ground return for the 3.3 volt power from the pi.
-
Pin 7 of the pi is the reed switch input:
- The 10k resistor is a "pull up" that defines the input (3.3) voltage when the reed switch is open.
- R2, R3, and R4 form a voltage divider that defines the input (0.3) when the reed switch is closed.
- Use a red or green LED.
-
The pair of wires to the reed switch can be anything you have laying around: telephone wire, sprinkler wire, speaker wire, etc.
-
The 560 ohm resistors in series with the reed switch are a half-ass attempt to protect the pi from damage.
- Control the sprinklers with the same pi?
- Why didn't I think of this before?
- mark the waterlog.txt file with sprinkler events
- color code and annotate the graphs with sprinkler info
- describe schedule with XML or JSON text file
- Use threads and queues
- thread_gpio adds sprinkler GPIO output to existing wet
- consumes sprinkler event queue
- writes to file queue
- maintaines valve state object
- thread_sprinkler
- determines desired valve state based on schedule, etc.
- writes to sprinkler event queue
- thread_file
- consumes file queue
- writes to waterlog.txt
- thread_gpio adds sprinkler GPIO output to existing wet