When built our house, we took measures to ensure that we would consume little energy to keep our place to live warm and cosy. For this, we added extra insulation, we kept the number of air leaks as small as possible, and added a ventilation system that recycles the energy from the extracted air into the fresh air that is brought into our home.
Since the proof of the pudding is in the eating, I need a way to monitor the resources used. A logical way to go is to tap into the existing utility grid meters. The meters are already in place, they are nicely calibrated (I hope), and they can easily be interfaced without having to fiddle with the interior of the meter itself.
What do I want to monitor: gas usage and water usage. Interfacing to the electricity meter is a bit more difficult, as it can spin in both directions in our situation (we also produce electricity). In the end, our yearly electricity consumption is covered by what we produce. I already monitor the production, so I feel little need in monitoring the main electricity meter.
Next question: how to interface with the meters? Several sensor types are available.
- Optical (the lowest digit of the meter has a reflective part) is not cool, as the interface will be influenced by lights being switched on.
- Infrared might be an option, but is like the optical a bit ugly. I can imagine that the meter-man is not keen on seeing some electronics glued in front of the meter readouts.
- Magnetic: closer inspection of the gas and water meter discloses some clues on the fact that the meters are prepared for electronic readout. For the gas meter, this is visible as a small rectangular indent in the meter housing right above the meter digits. For the water meter, a drilling is made in the side of the meter that is sealed with a removable rubber plug.
Aha, maybe a Hall sensor will do? In fact, both meters contain a magnet that is strong enough to trigger a Hall effect sensor. The sensor I use is a A3214EUA-T from Allegro Microsystems (Farnell order code: 1651972).
A test circuit is quickly built and shows that both sensors produce pulses when the meters are rotating. For the gas meter, I get a single pulse per .01 m3. The water meter generates a pulse for every .5 liter of water that is used.
Time to build a more robust circuit to measure the pulses. I decided to build an xPL enabled sensor node that can report sensor readings over the local network to my home server. The sensor node reports the readings through the sensor.basic message scheme and uses the type ‘count’.
The software is written in MPLAB and can be compiled with the free version of the Microchip C18 compiler.
The basic idea of the software is to continuously run the function ‘xpl_handler’ from the xPL lib that was written by me and Dirk. All events (sensor triggers, serial IO) are handled through interrupts. To offload the storage of received characters to the receive buffers of the XPORT (that device has 2k buffers built in) a software handshaking is implemented in the firmware.
The sensornode keeps track of the number of pulses that are produced by the Hall sensors and transmits an xpl-trig message when a pulse is detected. The server software can interrogate the accumulated pulses with an cmnd.basic message, after which the sensornode responds with a status message.
The device presents itself to the xPL network as ‘hollie-utilmon’.
The next screenshot shows the basic communication between the server software and the netnode for a single sensor readout.
Code is available in SVN.
On the PC side, we need a script to poll the sensornode are regular intervals. This is done with software of choice, and an example Perl script built on the excellent xpl-perl library is located here. This script pulls the values from the sensornodes and stores them in an RRD database for archiving and graph generation.
The data stored in the RRD database is then graphed. The daily usage statistics look like this:
I have not found a way to include the configuration of the XPORT in the SVN repo. Relevant settings are shown below.