IBM Bluemix: Monitoring Energy Consumption

Learn how to simulate an office building energy meter with IoTIFY network simulator and how to monitor power usage with IBM Cloud.

Introduction

IoTIFY network simulator with its powerful templates can be used to simulate a large variety of processes, either deterministic or with random components, and as such it is a valuable tool to understand how a real-world deployment of connected devices will look like. Data sent to the cloud by a simulated device can be monitored and analyzed, just like data sent by real-world devices, using your preferred data analytics tools. This tutorial will demonstrate these concepts with a practical example of an office building energy meter that sends power consumption data to the IBM Cloud IoT platform.

1. Set up a template in IoTIFY network simulator

Network simulator templates specify properties of network messages that simulated devices will send during a simulation. In this example, we are going to send messages from an energy meter to IBM Cloud. In our article “Integration: IBM Cloud” we explained how to set up IoT devices in IBM Cloud and how to configure a network simulator template so that a simulated device will connect to IBM Cloud using the MQTT protocol: refer to that article for information on how to configure MQTT parameters in the template. To simulate an energy meter, in this article we will use different message contents for our template: specifically, we will dynamically calculate the current temperature based on the time of day, estimate power consumption by the HVAC system to reach a desired temperature, and calculate total power consumption by adding a random value to the consumption by the HVAC system. As explained in our article “Integration: IBM Cloud”, MQTT message contents must be formatted usin JSON and must contain a top-level attribute named “d”, under which the data of interest are located. Our simulated energy meter will send the following data in each MQTT message:

  • current outside temperature

  • power drawn by the HVAC system to keep temperature inside the building at a desired level

  • total power drawn in the building, which will include the HVAC power and add to it a random component

To simulate the outside temperature at a given time, we use a simplified model where temperature ranges between a minimum and maximum value, increasing linearly from midnight to noon, and decreasing linearly from noon to midnight.

To keep things simple, we vary our simulated temperature at the top of each hour, so we are only interested in the hours of the current time. In our example we use an UTC+1 time zone (via moment().utcOffset(60)), i.e. we specify a 60 minute offset from the UTC reference time.

Next, we define a range for the simulated temperature, and a formula (using Javascript code) to calculate the temperature based on the current time; for example:

const minTemp = 10;
const maxTemp = 20;
var clockHour = hours % 12;
var range = maxTemp - minTemp;
var factor = clockHour * range / 12;
state.temperature = (hours < 12) ? (minTemp + factor) : (maxTemp - factor);

Given the outside temperature, the power needed by the HVAC system to keep the temperature inside the office at a given level (for example, 20 °C) is estimated to vary linearly with the difference between outside and inside temperature; in addition, we assume that the HVAC system is operated only during office hours, from 9:00 AM to 6:00 PM:

// HVAC is turned off except office hours, so power will be zero
state.hvac_power = ( hours < 9 || hours > 18) ? 0 : (20 - state.temperature) * 1000;

Finally, the total energy consumed in the building is calculated by adding a random component to the HVAC power; to do this, we use the normal() function of the chance.js library, with a mean value of 1000 and a standard deviation of 500:

// Add some random variation
state.total_power = state.hvac_power + chance.normal({mean: 1000, dev: 500});

The complete message contents in our template are as below:

{
    // get current hour in GMT + 1
    var hours = moment().utcOffset(60).hours();
    const minTemp = 10;
    const maxTemp = 20;
    var clockHour = hours % 12;
    var range = maxTemp - minTemp;
    
    var factor = clockHour * range / 12;
    
    state.temperature = (hours < 12) ? (minTemp + factor) : (maxTemp - factor);
    
    // HVAC is turned off except office hours, so power will be zero
    state.hvac_power = ( hours < 9 || hours > 18) ? 0 : (20 - state.temperature) * 1000;
    
    // Add some random variation
    state.total_power = state.hvac_power +chance.normal({mean: 1000, dev: 500});
    
    var myret = {
        d: state
    };
    return JSON.stringify(myret)
}

2. Set up data visualization in IBM Cloud

We are now going to set up IBM Cloud so that data coming from our simulated energy meter will be displayed graphically. For information on how to set up IoT devices in IBM Cloud you can refer to our article “Integration: IBM Cloud”. Once the basic setup is done, from the IBM Watson IoT Platform dashboard expand the left menu and click Boards:

Click Create New Board, then assign a name of your choice (for example, "IoTIFY") to the board, then click Next and then Submit. The newly created board will appear in the list of boards. Now, select the new board and click on Add New Card:

First, we are going to add a graphical visualization of temperature data coming from our simulator. Click Line chart: in the dialog window that appears, select the IoT device you previously configured and click Next:

In the next screen, click Connect new data set and insert the information needed to identify the temperature property in the data sent by the simulated device; specifically, the event name (in this example, "power_usage") must be consistent with the MQTT topic in the simulator template (in this example, "iot-2/evt/power_usage/fmt/json"), and the property name must equal the corresponding attribute name in the JSON object specified in the message contents:

Click Next, then go through the following steps of the card creation wizard keeping the default settings; at the end of this procedure, the new card will appear in the board (with no data if the network simulator is not running yet). To add visualization of power consumption data, follow the same procedure as done for the temperature, but specifying the HVAC and total power properties as data sets:

We can also add another card that will list all the attributes (hvac_power, temperature, total_power) of the device in numeric format; to do this, create a new card of type "Device Properties", then select our IoTIFY device as data source and connect 3 data sets, one for each attribute.

Now we are ready to start our simulation.

3. Start energy meter simulation

We can now start simulating our energy meter using the template we created in step 1. In the IoTIFY network simulator, define simulation parameters by selecting 1 as number of clients, and choosing a number of iterations and the gap between iterations, then start the simulation. As soon as the simulated device starts sending data, you can see this data visualized in IBM Watson IoT Platform:

Last updated