Introduction
Last year, I decided to analyze in detail my house’s electrical power consumption as I found it quite high, given the limited utilization of my home.
I googled around to find a relatively cheap solution. This post describes briefly what I did to measure the overall consumption, 7 days a week, 24 hours a day.
Implementation
The solution I implemented is based on a cheap energy meter by Eastron that was used, for example, for this interesting project.
The overall system is depicted in the following block diagram.
It is quite simple. A Linux embedded platform is used to periodically
- reads the power consumption
- uploads collected data to the cloud.
I used a cheap USB/RS485 converter to interface the embedded platform to the energy meter.
On the software side, I used this freely available library. I just implemented a very simple script to do the job:
pi@raspberrypi:~ $ cat /home/pi/energy-meter/script/em-read-cycle-cloud.sh #!/bin/sh # SDM120C # SDM120C ModBus RTU client to read EASTRON SDM120C smart mini power meter registers # # It works with SDM120C and SDM220 models # # It depends on libmodbus (http://libmodbus.org) # # To compile and install # make clean && make install # Usage: sdm120c [-a address] [-d] [-x] [-p] [-v] [-c] [-e] [-i] [-t] [-f] [-g] [-T] [[-m]|[-q]] [-b baud_rate] [-P parity] [-S bit] [-z num_retries] [-j seconds] [-w seconds] [-1 | -2] device # sdm120c [-a address] [-d] [-b baud_rate] [-P parity] [-S bit] [-1 | -2] -s new_address device # sdm120c [-a address] [-d] [-b baud_rate] [-P parity] [-S bit] [-1 | -2] -r baud_rate device # sdm120c [-a address] [-d] [-b baud_rate] [-P parity] [-S bit] [-1 | -2] -R new_time device # # where # -a address Meter number (between 1 and 247). Default: 1 # -s new_address Set new meter number (between 1 and 247) # -p Get power# -v Get voltage (V) # -c Get current (A) # -f Get frequency (Hz) # -g Get power factor # -e Get exported energy (Wh) # -i Get imported energy (Wh) # -t Get total energy (Wh) # -T Get Time for rotating display values (0 = no rotation) # -d Debug # -x Trace (libmodbus debug on) # -b baud_rate Use baud_rate serial port speed (1200, 2400, 4800, 9600) # Default: 2400 # -P parity Use parity (E, N, O) # -S bit Use stop bits (1, 2). Default: 1 # -r baud_rate Set baud_rate meter speed (1200, 2400, 4800, 9600) # -R new_time Change rotation time for displaying values (0 - 30s) (0 = no totation) # -m Output values in IEC 62056 format ID(VALUE*UNIT) # -q Output values in compact mode # -z num_retries Try to read max num_retries times on bus before exiting # with error. Default: 1 (no retry) # -j 1/10 secs Response timeout. Default: 2=0.2s # -D 1/1000 secs Delay before sending commands (wait line set). Default: 30=0.03s # -w seconds Time to wait to lock serial port. (1-30s) Default: 0s # -1 Model: SDM120C (default) # -2 Model: SDM220 # device Serial device, i.e. /dev/ttyUSB0 # # Serial device is required. When no parameter is passed, retrives all values #OUTPUT_FILE=log.txt OUTPUT_FILE=/dev/null DEVICE_FILE=ttyUSB0 #COMPACT_MODE=-q COMPACT_MODE= TOKEN= EM_ACTIVE_POWER_ID= EM_TOTAL_ACTIVE_ENERGY_ID= EM_TOTAL_ACTIVE_ENERGY_LAST_READ_TIME=0 CURL_PARAMS= populate_curl_params () { local __token=$1 local __var_id=$2 local __value=$3 local tmp tmp="-X POST -H " tmp=$tmp"\"Content-Type: application/json\" " tmp=$tmp"-d '" tmp=$tmp"{\"" tmp=$tmp"value\"" tmp=$tmp":$value}" tmp=$tmp"' " tmp=$tmp"https://things.ubidots.com/api/v1.6/variables/" tmp=$tmp$__var_id tmp=$tmp"/values/?token=" tmp=$tmp$__token #echo $tmp CURL_PARAMS="$tmp" return 0 } get_total_active_energy () { while : do sdm120c -t $COMPACT_MODE -P N /dev/$DEVICE_FILE >> $OUTPUT_FILE if [ -f EM_TOTAL_ACTIVE_ENERGY.var ] then value=`cat EM_TOTAL_ACTIVE_ENERGY.var` populate_curl_params $TOKEN $EM_TOTAL_ACTIVE_ENERGY_ID $value cmdline="curl $CURL_PARAMS" #echo $cmdline eval $cmdline return 0 fi done } echo "############################################" echo "Logging to : $OUTPUT_FILE" echo "Press [CTRL+C] to stop" rm -f /var/lock/LCK..$DEVICE_FILE while : do rm -f *.var date "+%Y-%m-%d %H:%M:%S" >> $OUTPUT_FILE # active power sdm120c -p $COMPACT_MODE -P N /dev/$DEVICE_FILE >> $OUTPUT_FILE if [ -f EM_ACTIVE_POWER.var ] then value=`cat EM_ACTIVE_POWER.var` populate_curl_params $TOKEN $EM_ACTIVE_POWER_ID $value cmdline="curl $CURL_PARAMS" #echo $cmdline eval $cmdline fi # total energy current_epoch=`date +%s` elapsed_time=`expr $current_epoch - $EM_TOTAL_ACTIVE_ENERGY_LAST_READ_TIME` if [ $elapsed_time -gt 3600 ] then get_total_active_energy EM_TOTAL_ACTIVE_ENERGY_LAST_READ_TIME=`date +%s` fi echo >> $OUTPUT_FILE sleep 1 done
This script reads every second or so the active power. Every hour, it also reads and uploads the total active energy drawn by the house. The script is run by rc.local every time the board is powered up:
# Start energy meter script /home/pi/energy-meter/script/em-read-cycle-cloud.sh
With regard to the cloud platform, I used the same I chose for the photovoltaic datalogger project, Ubidots.
Last but not least, I used one of the many cheap embedded platforms on the market supporting Linux and providing an Ethernet port and a USB port. I would like to take the chance to say, once again, that these platforms are convenient to build hobbyist projects like this one, thanks to the large availability of examples, forums, and accessories. However, I firmly think they are not suited for production-quality products addressing industrial applications. In other words, I would never build a real product with one of these boards.
Data visualization
Recently, Ubidots released the first beta version of their Android app. When using a mobile device to access your dashboard, it is undoubted that using the app is way more convenient than the browser.

Conclusions
This simple energy monitoring allowed me to realize that the overall power consumption is so high because of the heating. Specifically, I underestimated the consumption of the underfloor heating system. This is due to the fact that it makes use of energy-consuming pumps that are on for most of the day during the cold season.
Future work
In the future, I would like to use a second cloud platform too. In particular, I would like to upload data to IBM Watson IoT platform as well. I started to use it last year for a professional project related to Industrial IoT. This platform provides data analytics services which could be useful to perform advanced analysis of collected data. By the way, the Italian electrical company that takes care of national distribution network has recently started to replace their existing circuit breakers to achieve this goal.
Notes
Featured image source: http://maxpixel.freegreatpicture.com/Smart-Home-Smartphone-Home-Multimedia-Technology-2769210