The goals are:

  1. monitor in real time (every 10 sec) the total electrical power consumption of your house.
    1. In case you have 3 phases : you will be able to monitor each phase separately
    2. In case you have solar panels : it is also possible to measure the solar energy generated (this part is not explained in this instructable).
    3. moreover all this real time data is stored and
    4. dashboards can be easily created that display your historical power consumption data in various types of charts.
  2. provide a web application that allows to
    1. register any electrical devices in your house
    2. for each registered electrical device it will measure its power consumption by just switching it on or off and at the same time performing one click in the mobile application.
      • moreover all these device measurement events are stored
      • if the same device is measured multiple times: averages, min and max values are automatically calculated.

So thanks to this instructable you are able to get a much better understanding of your total electrical power consumption pattern and you can easily check any device in your house if it is consuming a lot of power when in use.

The main hardware components are

The main software components are

  • emoncms hosted for free on emoncms.org
  • emonhub, nodered, mosquitto, mongodb installed on raspberry pi

Step 1: Demo Videos

I have created two videos to demonstrate the 2 tabs of the web application:

  • the first video shows the registration of a new device that will be stored in the mongodb.
  • the second video (= most interesting video) shows the registration of a device event.
    Note that this video is bit truncated near the end but everything what I wanted to tell is in it.

Step 2: Hardware

The diagram above shows all the hardware that is needed. The purpose of this hardware is explained below.

  • [1],..,[4] = CT-clamps : these sensors measure the amount of current flowing through a wire based on induction.
    • Note that for this instructable you only need 3 CT-clamps. The CT-clamp number 4 you see is used to measure the power generated by my solar panels.
    • If you don't have 3 phases but only 1 phase coming into the house, you only need 1 CT-clamp.
  • [5] = emonTx v3 sensor node: this arduino based sensor node measures the power on the 4 CT-clamps every 10 seconds and broadcasts this data using the 433 Mhz Radio Frequency
    • the main advantages of this sensor node are:
      • budget friendly (see shop)
      • configurable through arduino sketches
      • this sensor node is also measuring the voltage, which makes it possible to check the direction of the power which is important if you are not only consuming but also producing power (e.g. with solar panels) as in that case the direction will change if more energy is produced than consumed
  • [6] =RFM12B is an expansion board that enabled the raspberry pi to receive the data broadcasted (433Mhz) by the emonTx sensor node. The latest version of this expansion board is now called RFM69PI.
  • [7] = Raspberry Pi 3 (Model B) will act as the "central server" for this instructable.
    • For this instructable I do not recommend to use a raspberry Pi 2 (Model B) as I think you will need the processing capacity of the pi 3 for a convenient user experience.
  • [8] = Home Router : This is your standard Home Router needed for:
    • giving internet access to your Raspberry Pi 3 [7]
    • giving Wifi access to your mobile device [9] to access the web application running on the Raspberry Pi 3 [7]
  • [9] = Mobile Device which might be a tablet, laptop or mobile phone:
    • it is used to access the web application in order to
      • register new devices and
      • register 1-click "device switch on/off events" that measure the power consumption of the device being switched on/off.

Step 3: Software

The figure above shows the main software components and the flow of data between those components. The purpose of these components is explained below.

  • [1] emonTx v3 3-Phase Sketch = the arduino sketch for the "emonTx v3" for 3-phases:
    • this sketch has the logic to monitor the voltage and the power of the 3 CT-clamps connected to it every 10 seconds and broadcast this over 433Mhz Radio Frequency so that a properly configured RFM12B [2] can receive this power data.
  • [2] RFM12B firmware = responsible for receiving the data broadcasted by [1] and assuring that the raspberry PI can access this date through the serial port /dev/ttyAMA0
    • Note that I didn't modify the preinstalled firmware.
  • [3] emonhub = a python program that receives the power data from [2] and is configured to forwards it to [4] and [5].
  • [4]emoncms = this application is hosted at emoncms.org. It receives the power data from [3] and stores it. In addition to that dashboards and charts are created that allows to see your historical and real time power data.
    • Note that it is also possible to install emoncms on the raspberry pi. In that case your are no longer dependent on internet connectivity.
  • [5] MQTT broker = receives the power data from [3] and forwards it to [6].
    • installed MQTT broker = mosquitto version 1.3.4 (build date 2014-08-22 06:10:51+0000)
  • [6]Node-Red = recieves the power data from [5], provides a web application for [7] which allows to register devices and device "switch on /switch off" events in [8].
  • [7] Web browser = is used to access register new devices and device "switch on/switch off" events using the web application provided by 6.

Step 4: EmonTx V3 3-Phase Sketch

I have installed a new arduino sketch on the emonTx v3 as I wanted to monitor 3 phases in combination with solar power generation but if you only wanted to monitor 3 phases or only one phase then the preinstalled sketch is most likely OK.

If you want to install a new sketch then the open energy monitor site nicely explains this at following location:

FYI I have also bought a USB to UART cable so that I can download a new sketch from my laptop to the emonTx.

Step 5: Emonhub

I have installed version "emonHub 'emon-pi' variant v1.2" as this version supports forwarding data to MQTT. Most likely newer versions will do equally fine. More information regarding the installation can be found at following links:

The emonhub configuration is specified in the emonhub.conf file.

I have also attached my emonhub.conf file. It specifies that the power data should be send to a local MQTT broker and to emoncms.org. Note that I have scrambled my emoncms apikey in the attached file.

Step 6: Emoncms.org

I have created an account on emoncms.org. This will give you a Write API key that you need to specify in your emonhub.conf (see previous instructable step).

If emonTx and emonHub are configured properly you should see events appearing when navigating to https://emoncms.org/input/view (see also my screenshot attached to this step).

Once this is done you can create feeds, graphs and dashboards. FYI I have attached 2 dashboards I have created to this step..

Note that it is very easy to zoom in / zoom out in a particular chart.

Step 7: Mongodb

Mongodb is db where you can easily store json data which makes it very interesting for Node-Red applications.

1/ I have installed mongodb version 2.4.10 on raspberry pi using following commands:

sudo apt-get update<br>sudo apt-get install mongodb
sudo service mongodb start

2/ To limit the number of write operations on my raspberry SD card, I have configured mongo so that it writes the data to the USB hard disk connected to my raspberry pi. To do this you must update dbpath in /etc/mongodb.conf.

FYI I have used following steps to move my mongodb to USB hard disk location :

1/ sudo service mongodb status
2/ cd /var/log
3/ sudo mv mongodb /mnt/wd1tb_media/media/data/mongodb
4/ update /etc/mongodb.conf
... <br># Where to store the data. <br># dbpath=/var/lib/mongodb <br># <br># JVA 2017-01-30 moved mongodb to harddisk<br>dbpath=/mnt/wd1tb_media/media/data/mongodb<br>...
5/ sudo service mongodb start

3/ I created a database with name "power" using the command "mongo".

4/ I have also setup security so that only user pi can access this "power" mongodb:
For this:

4.1/ I have added user pi using following commands:

pi@pi3one:/etc $ mongo<br>MongoDB shell version: 2.4.10<br>connecting to: test
Server has startup warnings:
Sun Jan 29 22:28:38.851 [initandlisten]
Sun Jan 29 22:28:38.851 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
Sun Jan 29 22:28:38.851 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
Sun Jan 29 22:28:38.851 [initandlisten] **       See <a href="http://dochub.mongodb.org/core/32bit">  http://dochub.mongodb.org/core/32bit

Sun Jan 29 22:28:38.852 [initandlisten]
> use admin
switched to db admin
> db.addUser('pi', '<password><password>');
        "user" : "pi",
        "readOnly" : false,
        "pwd" : "c083095458cc09348d767fa7cb111196",
        "_id" : ObjectId("588e6937e564948f4b391639")

4.2/ I have also modified /etc/mongodb.conf (see attached file).

Step 8: Node-Red Configuration

Node-Red is very powerful visual wiring tool for creating Internet of Things application.

  1. I have upgraded my node-red installation to version v0.16.1 on my raspberry pi using the following instructions:
  2. Once you have installed this version, then you open node-red URL in your browser (e.g. in case is the IP address of your raspberry pi).
    1. select "manage palette" from the pop-up menu in the upper right corner.
      This should make the install tab visible at the left of your screen.
    2. in the install tab enter "node-red-node-mongodb" and install that node.
      This should install version 0.0.10 of node-red-node-mongodb
      This node allows to make connections to a mongodb.
    3. in the install tab enter "node-red-dashboard" and install that node.
      This should install version 2.2.1 of node-red-dashboard
      This node allows to create web applications.

The Node-Red application consists of the following 3 flows which are detailed in following steps:

  1. emonTx flow : receives power data events through MQTT and forwards them to the register event flow.
  2. register device flow : provides the web application tab "register device" through which it becomes possible to specify new electrical house device which will be stored in the mongodb.
  3. register event flow: provides the web application tab "register event" through which it becomes possible to register a switch on / switch off event for any of the devices that you have registered through the "register device" tab.

Step 9: EmonTx Flow

This is a very simple node-red flow.

  1. It has a node "emonTx" that connects to MQTT and listens to the topic "emonhub/rx/10/values" that is used by emonhub for sending the power events.
  2. "The extract power and add timestamp" function converts the power data in more readable json format and add a timestamp to it.
    1. In the attached screenshot: the debug tab shows at the top the raw message received from MQTT and below it the message produced by the "The extract power and add timestamp" function.
  3. The nicely formatted power event with timestamp is forwarded to the "register event flow".

Step 10: Register Device Flow

The register device flow (see attachment) defined the register device tab of the web application (see attachment). This tab makes it possible to register new devices. Those devices will be stored in the "device" collection of the "power" mongodb (see also attachement).

Note that this flow assumes that your house has 4 floors (see attached screenshot). This can be adapted if you want. But if you do so - you should also adapt the "floor" node in the register event flow.

The function node "return rooms for floor" (see screenshot) hard codes the rooms for each floor. This node you should adapt for your house / apartment and you should also adapt the "return rooms for floor" node in the register event flow.

Step 11: Register Event Flow

The register event flow defines the "register event" tab of the web application.

This tab allows to:

  1. select a specific device (if your device doesn't exist yet, you can create it using the "register device" tab !)
  2. click on the "switch on" or "switch off" button: when clicking on these buttons you must also "switch on" / "switch off" the actual device you have selected.
  3. Once you have clicked on the "switch on"/"switch off" button, this flow will store the power data received from the emonTx flow for 3 periods (one just before the button click and 2 periods just after the button click) together with the event info.
    1. the flow status and event info is shown in real time in the "status" section.
    2. Note that there are 5 possible statuses for this flow (see attachment).
  4. The event information is also shown in this section.
  5. Once the data for the 3rd period is retrieved, the deltas are calculated for each phase and also displayed in the event info (see point 4). Using the store event section the user can decide if he wants to store this event or not.
  6. The power consumption chart shows the consumption for the 3 phases in real time. Updating of this chart is temporarily stopped when the user needs to decide to store or ignore the event data.
  7. The event statistics section shows the event statistics of all stored events for the currently selected device. This section is in real time updated.

Step 12: End

That is it. I hope my instructable is sufficiently clear. Nevertheless all questions and comments are more than welcome.

Warm Regards


<p>very interesting, I didn't know the emon sensor node. Thanks for shared</p>
<p>Lots of good tips, thanks for sharing :)</p>

About This Instructable




More by jan_vda:1-click Power Measurement of Any Device in Your House 
Add instructable to: