Sunday, March 10, 2013

Monitoring an analog power meter

Update 10-11-2013: The system is working very good (better than expected :), I have had very little down time. Biggest issue is that the SD card ,with the root filesystem on it, is breaking. Do not use a journalling filesystem on flash media, this will wear down the NAND very quickly. Most SD cards and USB sticks do not do wear-levelling! I've added all files to Github, easier to use than a single ZIP file, check out for the sources (and my power usage from the past months).

This post contains a description of my home-build analog power meter monitor. This setup allows you to get an accurate power usage overview by counting the revolutions of the meter disc visually with a webcam. You can download the entire package (without any warranties etc..) here to try this yourself.

What do you need:
  • An analog power meter
  • A USB webcam
  • Some computing power to run motion detection


For computing power I use a UG802  This is a pretty powerful Android HDMI/WIFI stick and has a USB connector for all kinds of peripherals. I have a connected a USB webcam combined with a 5mm white LED to make it work in the dark.

By default the UG802 is running Android. This is not very useful for this kind of project, plain Linux is preferred. There are many guides available on running Linux on the UG802. Check here and here.


An important part of the system is a library called "motion", a motion detection library. The library is very configurable and works with USB cameras but also wireless models. Motion can be installed by running: "apt-get install motion", no patches or changes required.

Motion is installed as a service and automatically starts on boot. You do need to configure the library in /etc/motion/motion.conf. There are lots of settings in here, important settings for this setup are "threshold", "noise_level", "noise_tune", "gap", "area_detect" and "on_area_detect". Depending on your meter, you might have to do some tuning to the config. All values are well documented in the standard config file.

The "area_detect" value lets you select 1 out of 9 areas in the image that can trigger motion, this filters unwanted motion in other areas. You can even create a "mask" image that overlaps only the rotating disc. The "on_area_detect" allows you to execute a command when motion is detected. I used this to send a signal (SIGUSR1) to a counting application, whenever the disc rotates, a signal is sent and  a value is added to the power total. I attached my motion.conf at the end of this post.


This is the name of my application that counts the rotations from the disc. As mentioned above, these pulses are delivered to this application by a signal. The collector sums the rotations every 10 minutes and adds these values to a csv, also a daily total is logged. The source code of this application can be found below. You can run the application on startup by adding it to rc.local or just start it in a screen session.

Web interface

I've created a simple front-end that displays the interesting values via a web interface. I've found a nice graph rendering library called highcharts/highstocks.  Highstocks allows you to set the x-axis of the graph to a certain period. Besides the charts I've added a live view of the camera and installed the phpSysinfo package. I've installed the following packages for this:
  • lighttpd
  • php5-cgi
  • fastcgi
Please note that the highchart csv parser I use does not like new-lines at the end of the csv file. You can remove these with vim ":set noeol" and ":set binary".

See for sources and configuration files.

1 comment:

  1. Godd idea, very useful as a complete project, my SIGUSR1 has been rerouted to a Python script. That's the only difference.