Monitoring power consumption with a Pi

The other day a friend of mine asked me how to monitor remotely the usage of an ordinary electric device (e.g., a lamp, or a televisor). The idea is to measure regularly the power consumption of the device, and send regularly reports on this consumption.

A simple need, to which there are multiple responses. Nowadays, it is easy to find “smart plugs”, which are devices to be plugged between an electricity outlet and the cable connecting the device. The device can then be controlled remotely by WiFI, and some of them are capable of monitoring energy (see for example here)

While such devices are usually quite inexpensive, they suffer from a common flaw: all of them rely on a smartphone application to be controlled, and to connect energy consumption data. While this is very convenient in many cases, it is not so useful when one wants to process “in a special way” the data. For example, if the purpose of the monitoring is to detect over- or under-usage of the device monitored (e.g., receive an alert if a training device has not been activated for a given period of time), the mobile applications are usually not flexible enough to allow for such configuration.

Hence, the idea to use a Raspberry Pi to perform the collection and the monitoring of the power consumption, and via a simple and flexible Python script, to program the analysis of the data, and the broadcast of an alert if necessary (e.g., via SMS, using the same method as the one described here).

The main need is a sensor able to measure the power consumption from AC current power (in 220 V or 110 V). And if possible to do it in a safe way (toying with 110V/220V electricity is NOT risk free !)

After some scooting I found the following sensor, which can be simply installed AROUND the electric wire to measure power consumption (hence, no risk with playing with the electricity)

This is referred as a “non invasive AC current sensor”, made of ferrite which should be put around a pair of electric wires — and for better result, one of the two wires !

The sensor needs a board to collect its data and transfer to the Raspberry Pi. I chose the one developed by LeChacal for the Pi Zero. It is straightforward to install it, and comes with detailed instructions on how to make it work.

After a few back-and-forth, I managed to get it to work in a fairly easy way: I plug the device to be monitored via the extension cordon where I have installed the sensor, and via a python script (contact me if you want a copy of the script) the Pi sends regularly the data collected via email and alerts via SMS.

For example when monitoring the consumption of a TV set, this is what you get — The TV was mostly on till midnight, then off (with a small remaining power consumption)

I haven’t calibrated the data to translate the measure into Wh, but to control the usage of a device, the system is operational.

Easy !

One thought on “Monitoring power consumption with a Pi

Leave a comment