I'm going to try to throw together a quick energy consumption logger so I can see where my elec and gas is going. I don't have smart meters, but my meters do have pulse outputs (albeit the gas meter is mechanical). I'm planning to use optical sensors to detect the pulses, then an RPi to count pulses per minute (or whatever) and write to SD card. I won't bother with realtime or timestamping, and I can process all the pulse counts logs in Excel or Matlab to get kWh graphs, etc.
Files
UtilityMeterLogger2.ino
Arduino code for the logger. Version 2: now with two temp sensors.
I bit the bullet and ported the visualisation code over to Python/Pandas/Matplotlib, but in doing so finally got tired of the need to 'guess' at the timestamps from the record number and rough idea of the time between records. So I bought a cheap RTC module and have hooked that up now. Things are much better now, plus if there's an interruption to power the logger will resume automatically with the correct time, and no data is lost.
Important note about the RTC module: it has a charging circuit for a LIR2032 rechargeable coin cell, but a non-rechargeable CR2032 cell was supplied fitted (with the possible risk of smoke/fire/etc). So I swapped that out.
One more change: the Arduino now automatically determines the switching thresholds for detecting pulses via the analogue input (the gas meter) at start-up, so if I don't quite put the sensor in the right place each time, it doesn't matter. Previously they were hard-coded and it didn't always detect the pulses.
I thought it was about time to resurrect the energy monitor, especially now that energy prices are skyrocketing. No major changes, just a change to how the temperature sensor interface was done so that I can now have two sensors: one indoors, one outdoors. Looking forward to getting some interesting data this winter.
After something like two weeks, the plots are showing some really interesting stuff, like the effect of sunlight hitting the temperature sensor at about 10:45 each day.
Might see if I can add a second temperature sensor for logging outside temps.
Everything seems to be logging nicely, and I've added a DS18B20 temperature sensor to grab indoor ambient temperature too. The only minor niggle so far is that the logs are not quite 60 seconds apart (perhaps the resonator clock isn't very accurate) but that's easily accounted for.
I've written a bunch of Matlab code to read in the log file and produce pretty plots like this:
Now I just need to wait for the cold weather to arrive so I can switch the heating on!
I found an OPB704 kicking around and added a couple of resistors to bias it up for 5V operation.
390Ohms on the diode side biases it at about 10mA forward current from 5V supply. A 10kOhm on the phototransistor (collector) results in an almost complete rail-to-rail swing when something white is placed in front of the sensor.
Here's a screenshot of the ADC values as the 1/10ths wheel goes round on the meter:
Also just bought a light sensor module (with on-board comparator and threshold adjust) for £2 for the electricity meter sensor - perfect! Won't even need an analogue input pin for that.
...which gives a strong pulse every 10dm3 of gas consumed (and nine weaker ones for the in-between digits).
The method is not too dissimilar for the electric meter (which has a flashing LED for every 1Wh consumed).
I might use an Arduino instead of RPi (if I can get logging to SD card working easily) because it offers analogue inputs so I can easily add e.g. temperature sensors later, and maybe do all the optical sensing in software instead of needing a couple of opamps. This page looks useful:
I save $500/year without lowering the thermostat. https://sites.google.com/site/nodemcu12e/home#h.iu580v501qb5
MQTT is a good way to monitor and control from anywhere.
https://sites.google.com/site/nodemcu12e/home#h.bagvjtiwx7l3