There are quite a few things we take for granted in our day-to-day lives. Public utilities are one such example. We assume that the electricity and water supply will be at our disposal 24/7. This leads to wastage, and excessive wastage and malpractice lead to further deterioration of the environment. Thanks to the awareness around climate change and the advancements in renewable energy sources, we are in a better position to safeguard our future generations by ensuring a sustainable supply of energy for our day-to-day needs. Still, a lot needs to be done toward achieving self-sustained living and this is where technology can help us. In this blog post, we present yet another amalgamation of things that can be managed using that game-changer, the “Internet of Things.” In this case, it’s an IoT energy management system for tracking electricity supply and consumption.

Note: This blog post was originally published in the IBM Bluemix Blog

IoT Energy Management With Smart Grid

Smart energy grids are already in place, and we see a boom in this space with innovative business models like energy credits which can immensely benefit the consumers. But for a homeowner, this comes with the added complexity of having to install more components. For starters, there needs to be a renewable source of energy—either a solar panel or a wind turbine—along with an energy storage system. We also need a net metering system, which is a special kind of electricity meter that tracks both the energy consumption as well as the generation from a household and rolls back the meter in case of excess generation given back to the grid.

A lot of data gets generated by these systems, and this is where IoT can help in harnessing it for our best interests. If we accumulate this per household data and combine with a smart grid, then there is potential to offer insights at the town or city level, which can help in framing benevolent policies for energy security.



Project Overview

For this project, we have tried to replicate the electricity distribution of a household by using a solar panel, a few appliances, and a battery, which acts as the electricity supply from the grid. A web-based dashboard acts as an IoT energy monitoring system and tracks the whole system via IBM Bluemix hosted portal.

Below is a block diagram for this replicated setup for a single household.



There are two loads, “LOAD 1” and “LOAD 2,” representing a light point and a fan point in the house. Also, there are three sensors, labeled as “CURRENT SENSOR 1,” “CURRENT SENSOR 2” and “CURRENT SENSOR 3.” These are current sensors used for sensing the magnitude of current through the various paths of household electricity distribution.

  • CURRENT SENSOR 1 measures the excess energy given back from the solar panel to the grid in case of underutilization.
  • CURRENT SENSOR 2 measures the total energy consumed from the solar panels
  • CURRENT SENSOR 3 measures the total energy consumed from the grid.

The data captured in these sensors is in the form of Amperes, which is the unit for measuring electric current passing through the wire. The sensor readings are accumulated in a controller (Arduino YUN) and sent to the Bluemix cloud where they can be analyzed via a dashboard.

Note: For the sake of simplicity, this setup is based on the Direct Current (DC) system, as opposed to the Alternating Current (AC) system deployed all over the world for commercial electricity distribution.

Measurement Parameters

Using the current sensors, we can sense a few meaningful parameters such as

  • Power Consumption/Generation: Amount of current consumed by the household and generated by the renewable sources in the household. This is also known as the Watts (or Wattage).
  • Energy Consumption/Generation: Amount of energy consumed or generated by the household. This is a function of power consumption over a period of time. The standard unit of measuring this is KiloWatt/Hour (kWh). By measuring the kWh of consumption vis-a-vis generation, we can find how energy efficient the household truly is.

Data Push and Cloud Storage

All the sensors are connected to Arduino YUN controller, which also acts as an energy monitoring unit. It takes a sample of the sensor readings at periodic intervals and then pushes them to the cloud. To do this reliably, we have used PubNub. PubNub provides a data streaming service for sending data across the internet in real-time, with the utmost reliability and security.

Data storage on the cloud is facilitated by the IBM DashDB data warehousing technology.


Both PubNub and DashDB are available as services within the IBM Bluemix catalog of services.

Project Setup

There are three components in this project.

  1. IBM Bluemix based energy monitoring server, which captures the net energy consumption data from the energy source and loads in the setup.
  2. Web Dashboard, which provides a real-time view of energy monitoring.
  3. Electrical network, which models the regular electricity supply and distribution within a house. This network also includes an Arduino YUN based controller and sensors for measuring the energy at various points within the network.

The complete source code along with build and configuration details are available the shyampurk/iot-for-utilities project on GitHub.

Energy Monitoring Server

The energy monitoring server program is based on Python and is hosted in IBM Bluemix platform. This application also relies on two Bluemix services, DashDB and PubNub. DashDB is IBM’s in-house database platform for data warehousing needs. PubNub is one of the third party services available under Bluemix catalog which offers a real-time messaging service over the internet. Refer to the steps in README file to understand how to setup and host a python application under Bluemix with DashDB & PubNub.

The source code for this energy monitoring server is located under powerGrid_server directory in the GitHub repository.

Web Dashboard

This is the user interface for monitoring the energy consumption of the model electrical network used for this project.

The web dashboard is hosted on Bluemix, as part of the server application. The communication between a web client and energy monitoring server is orchestrated via PubNub.

The source code of web dashboard is located in powerGrid_webApp/IOTEG directory under the GitHub repository.

Electrical Network

The electrical network is modeled using a solar panel supply and a battery supply ( representing the actual Grid supply). Two loads, a light, and a fan, act as the electrical devices whose consumption pattern need to be tracked. Three sensors are connected to the network, and their measurements are fed to the Arduino YUN controller.

Here is the schematic diagram of this project.

IoT For Utilities Monitoring Schematic

The battery charging circuit in this schematic represents the part of the electrical network which gives back excess energy generated from the solar panel, back to the Grid (the battery in our case). This happens when the energy consumed by the loads is less than what is generated from the solar panels.

The Arduino YUN runs an OpenWRT Linux images which continuously monitors the sensor readings and pushes them to the energy monitoring server every second. PubNub also orchestrates the communication between Arduino YUN and the energy monitoring server.

The source code for the program running under Arduino YUN is located under yun_pubnub & device/current_sense_new directories under the GitHub repository.


PubNub acts as the communication middleware for the entire system. It provides a cloud-based real-time Data Stream Network which supports more than 70+ SDKs, such that it can enable any device to communicate with any other device on the Internet. This application uses three of PubNub’s SDKs for all components to seamlessly communicate with each other. These are:

Building The Hardware Setup

The Hardware and overall electrical network setup of this project is a little complex than the usual. To simplify things, we can divide it into four steps.

  • Step 1: Power Supply
  • Step 2: Solar Panel Supply
  • Step 3: Battery Charging Circuit
  • Step 4: Final Assembly

Refer the hardware build section under README file to see how the hardware is built.

Get, Set Go !

Once everything is setup regarding the hardware, we have to ensure that our energy monitoring server and its associated services are up on Bluemix dashboard.

Now we are all set.

Fire up the circuit. Launch the web dashboard, and we are all set to track the energy consumption and generation status of this system. This is the model IoT energy management system in action!

As you can see, the sensor gauges show the readings of the total energy generated from the solar panel, total energy given back to the grid and total energy consumed by the loads. With the light on, the energy consumed is less than generated by the solar cell. Hence the grid supply is not utilized. But with both light and the fan in on state, the consumption exceeds the generation and hence the grid is called into action.

Practical Uses of IoT Energy Management and Tracking

Why would you want to track energy? Apart from the obvious reasons of monitoring and auditing, there are some practical benefits of this.

  • Proactive tracking: Maintaining a periodic moving window average of the energy consumption pattern can help keep things in check and help drive future consumption forecasts. It also helps in generating alerts in case of abnormal deviation from the normal or predicted pattern.
  • Preventive Maintenance: All energy producing sources have an inherent capacity which decays with time. Take the case of a battery. The energy output decays over time and this can be measured and can be acted upon well before a complete breakdown cripples the system.
  • Fault Identification: Electrical appliances do suffer from faults from time to time. This could be a case of outage due to fault in the wiring or connectors, or it could be due to drawing excess current by an old appliance which is not meeting the energy star compliance.
  • Monetization: As mentioned earlier, net metering can provide some benefits to homeowners by charging them for the net energy consumed. This is a great incentive and can significantly boost the development and sales of alternative, renewable sources of energy.


This project portrays the possibilities of a connected economy of essential services. With every industry getting revitalized with the new landscape of business and service model possibilities, electricity supply and other utilities industries are also evolving towards a smarter world.

Be leveraging the IBM Bluemix ecosystem, we have shown you how we can elevate the concept of connectedness to a new level and assist enterprises and utility service providers to scale up their offerings as per the trends. This is also an exciting area for IBM Watson as the amount of data generated is huge and deriving practical benefits of energy tracking from that data could become the real game changer in the medium to long-term.

About the author Staff

Showcasing and curating a knowledge base of tech use cases from across the web.

  • Great work with the power monitoring device. You have explained everything clearly. But, I found this article late though. I have already installed OHM Assistant at home. OHM Assistant is an energy monitoring that tracks all the electricity consumption and gives detailed information on my mobile.

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
    TechForCXO Weekly Newsletter
    TechForCXO Weekly Newsletter

    TechForCXO - Our Newsletter Delivering Technology Use Case Insights Every Two Weeks