xPL enabled utility meter monitor
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’.
Hardware
The node is built around a PIC18F2520 and an XPORT. Both are mounted on the netnode PCB that I designed previously. PCB and schematics are available here.
Firmware
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.

Next to sensor reporting, the firmware of the netnode also supports initial configuration of the name of the netnode in the xPL network. Filters and group membership is currently not supported.
Code is available in SVN.
Software
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.
Results
The data stored in the RRD database is then graphed. The daily usage statistics look like this:


XPORT configuration
I have not found a way to include the configuration of the XPORT in the SVN repo. Relevant settings are shown below.





johan said,
Wrote on June 28, 2010 @ 9:46
Lieven,
Ik leer altijd wel iets bij van Uw elektronica bezigheden. Zo heb ik hier de Xport ontdekt.
Wat die xPL betreft, ik kan niet direct fabrikanten vinden die kant en klare sensors op de markt brengen….die ik dan op mijn LAN zou kunnen aansluiten
Kan je mij a.u.b eens de juiste weg wijzen.
Lieven said,
Wrote on June 28, 2010 @ 10:54
Hallo Johan,
ikzelf heb geen weet van ‘ready-made’ hardware die xPL ondersteunt. Reden te meer om het zelf te bouwen natuurlijk
Ik zou zeggen: best eens een berichtje posten op het forum van http://xplproject.org.uk/
Groeten!
Lieven.
icarus75 said,
Wrote on July 2, 2010 @ 11:49
Dag Lieven,
Heel knap van je om met dit type Hall sensor de omwentelingen van de meter in pulsen om te zetten!
Ik heb hetzelfde type water meter dan die van jou. Binnenkort dus eens experimenteren met een Hall sensor. Ik vraag me wel af waar de tweede opening dan wel voor dient?
Flukso is ook een open source hard- en software project voor het visualiseren en on-line vergelijken van (energie)stromen in het huis. We hebben tot hiertoe vnl. gefocust op het meten van het electrisch verbruik met stroomklemmen. Wanneer je het aansluitpunt van je PV invertor uitgang in je meterkast juist kiest, dan kan je zowel PV productie als consumptie apart meten. Ook wanneer je netto stroom aan het net levert.
Cheers!
Bart.
Lieven said,
Wrote on July 3, 2010 @ 11:50
Dag Bart,
die tweede opening is volgens mij intern voorzien van schroefdraad, dus mogelijks dient deze gewoon om de sensor+een printje vast op de meter te bevestigen.
Die Flukso: ziet er mooi uit! Ik ben ‘tempted’ om er eentje te kopen, het matched eigenlijk zeer goed met wat ik gemaakt heb om mijn PV installatie te monitoren. Ik ben momenteel aan het spelen met de devices van Plugwise voor de monitoring van de verbruikers, maar die devices hebben het nadeel dat het hele platform closed is. Niet dat dit natuurlijk verhindert dat ik het toch kan inpassen in mijn meetsysteem, maar handig is anders…
Dan is het open model van Flukso zeker een voordeel!
Groeten,
Lieven.
icarus75 said,
Wrote on July 3, 2010 @ 5:00
Dag Lieven,
Jullie hebben ook een knap stukje open hardware ontwikkeld door het koppelen van een PIC aan een Xport. Van xPL had ik tot hiertoe nog niet gehoord. Daar moet ik nog wat meer over lezen.
De Fluksometer heeft zowel analoge als digitale ingangen. We gebruiken de digitale ingang voor het aansluiten van de open-collector S0 uitgang van een DIN-rail kWh meter (zoals die van de GSC teller). De Hall sensor switch van Allegro heeft ook een open-collector uitgang. We gaan dus enkel de meterconstante correct moeten bepalen en instellen.
Naast rapportering naar de Flukso server, hebben we ook een demo versie draaien die een locale JSON/REST type interface aanbiedt (work in progress!). We willen dit gaan combineren met het Avahi/Bonjour protocol voor
service discovery alle in de LAN aanwezige sensoren.
Ik verwijs je ook naar een blog post van David Rowe die toont hoe je je PV productie en huishoudelijke consumptie apart kan meten: http://www.rowetel.com/blog/?p=135.
Cheers!
Bart.
Lieven said,
Wrote on July 3, 2010 @ 8:53
Hoi Bart,
die PIC + Xport (ik noem het de netnode) gebruik ik ondertussen een beetje voor vanalles in huis: rolluiksturing, gas/water teller monitoring, zonneboiler en PV monitor, balansventilatie monitor. Alle benodigde firmware en software is open en ik log alles in RRD databases, net als jij doet.
Alleen heb ik het niet opengetrokken naar het web. Dit betekent dat ik een energiezuinig servertje heb op het LAN vanwaar alle sensorwaarden gepolld worden. Voordeel is dat ik alles intern heb en dat ik kan knutselen zoveel ik wil, nadeel is dat als er mensen zijn die mijn opstelling willen dupliceren, ze ook een servertje nodig hebben.
En ik heb er ook geen professionele enclosure voor zoals jij die wel hebt!
Maar nu weet ik in ieder geval al naar wie ik ze kan doorverwijzen als ze hun PV installatie willen monitoren he
Pieter Meulenhoff said,
Wrote on September 2, 2010 @ 1:54
Lieven,
Leuke website! Zou je mischien ook het circuit wat je voor de Allegro Hall sensor hebt gebruikt kunnen beschrijven? Heb je een plaatje? Ik heb dezelfde Hall sensor en dezelfde gasmeter, maar het lukt mij niet om er signaal uit te krijgen.
Ik heb zelf +3V op pin1, GND op pin 2. Pin 3 is aangesloten op de analoge input van een Arduino. Tussen pin 1 en pin 3 heb ik nog een weerstand gezet van 1K.
Groeten,
Pieter
Lieven said,
Wrote on September 2, 2010 @ 8:38
Dag Pieter,
ik gebruik een gelijkaardig circuit als jij doet (het is een PIC ipv een Atmel controller, maar dat doet er niet toe). Belangrijk is dat je inderdaad een pull-up weerstand hebt naar Vcc. Let er echter op dat deze weerstand groot genoeg is! De Hall sensor kan maar maximum 1 mA sinken. Als jij 3V met een 1k pullup op de output aangesloten hebt, dan probeer je 3 mA door de chip te jagen… Mag ik trouwens eens vragen hoe jij die 3V gemaakt hebt? Is dat de Vcc van de Arduino? Is dat dan niet 3V3 of 5V?
Verder is het wel zo dat je enig experimenteerwerk zal hebben om de juiste plaats te vinden om de sensor op de gasteller te bevestigen. De logo-zijde van de sensor moet naar het telwerk gericht zijn, en dan recht boven het laatste wieltje geplaatst worden.
Vriendelijke groeten,
Lieven.