I called my natural gas provider one day, and asked if it was possible to get some kind of output port on my gas-meter so I could monitor how much gas I use. "No we don't allow that. The meter actually already have an impulse output but we plan to use that in some years time." I asked if I could "borrow" that output until they needed it, but the answer was a flat and firm no.
Now, there are two things which piss me off about that, it is one thing that I already paid them for that impulse output, but knowing what I know about computers and bureaucracies, that port is never going to be used for anything.
Somebody, somewhere, had this vision of electronic meter reading, and managed to arrange for all meters to have a pulse output, probably costing all gas-customers extra for the feature, but tickle me with a pole if that will ever be implemented.
Anyway, I have better things to do that to fight windmills and gas utilities, so I started to ponder how I could get hold of the data I wanted in some other way.
A closer examination of the gasmeter showed no signs of where the built-in impulse output were located, leading me to conclude that it probably is somewhere inside the sealed section of the meter where it would get me in legal trouble, not to mention potential explosion hazard to fiddle with it.
But I did notice something else: it is implemented optically rather than mechanically because the zero on the least significant digit i a shiny metalic oval rather than a painted white numeral.
I tried to get a photo which could show it, but I didn't have too much luck. First off, my gas meter has a tendency to not stand still with that zero digit in view very often, and second I don't use much gas right now so I got tired standing out in the cold of waiting for the perfect photo-op. Nontheless if you look at the picture at the right you can see that the zero is coming into view under the digit nine and you can see that it is entirely unlike the zero on the next digit.
So all I had to do was to find an optical sensor which would be able to spot that zero and I would be in business. A bit of searching landed me on the OPTEK OPB704 (Used to be Fairchild) which is almost perfect for the job.
Inside this device is an infrared LED and a photo-transistor which both point at a spot some 4 mm in front of the device.
The LED just needs some power, up to 50mA but a bit of experimentation showed that even 5mA is plenty for good response. The phototransistor starts conducting current when hit by infrared light reflected of whatever target is in front of the assembly.
Mounting the sensor on the gas meter was easier than I had feared. Obviously anything which could be construed as "permanently attached" to the meter would be reason for the gas-utility to balistic. Fortunately I found that one of those pesky back-panel blanks from PCs was just the right bit of hardware.
The top bit of the blank had a notch to which I could bolt the sensor and after a bit of bending the entire thing could be taped to the outside of the gas-meter with some regular packing tape.
I wired the sensor up with a leftover high-quality RS-232 cable I had lying around, only four wires and a shield were needed so I had no need for the white wire which is why that looks a bit weird on the picture.
I have about 7m of wiring on my sensor, but all things considered I think it could easily run three times as far with that quality of cable.
I used a standard parallel port to interface to the computer so getting power for the LED was just a matter of using enough of the data outputs. I settled on three outputs though a 68R resistor which gives roughly 20 mA through the LED. Max rating is specified as 50 mA.
The phototransistor was not quite strong enough to pull down the "ACK" input of the parallel port so an extra transistor was needed as driver for that. A randon NPN from the junkheap did the trick. Some experientation was needed for the resistor, initially 3k3 seemd to work fine, but when the outside temperature dropped to -5C it failed: the phototransistor could no longer transition the input reliably. Using 6k8 has so far worked reliably down to -12C.
I added a 10nF capacitor across the photo-transistor to kill any induced high-frequency noise because the input on the parallel port has a quite good frequency response. I have seen no false pulses with the capacitor in place.
The physical constuction is nothing fancy, a bit of experimetors PCB directly in the shell of the D25 connector.
(The picture is from before the change to a 6k8 resistor)
In FreeBSD the "pps" driver provides access to the PPS-API which can be used to report the exact time of the pulses on "ACK" pin of the parallel port.
I'll describe the software here when I finish it, but my interrim kludged up stuff produces nice graphs like the one shown here using RRDtool.
I have found no documentation for the rather weird burn pattern of my Vaillant gas-unit; it seems to be intentional.