Monitoring Energy Consumption
Learn how to simulate an office building energy meter with IoTIFY network simulator and how to monitor power usage with IBM Bluemix.
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 Bluemix IoT platform.
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 the IBM Bluemix IoT platform. In our article “Connecting to IBM Bluemix” we explained how to set up IoT devices in IBM Bluemix and how to configure a network simulator template so that a simulated device will connect to IBM Bluemix 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 “Connecting to IBM Bluemix”, MQTT message contents must be formatted in 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.
First, we retrieve the current time of day using the moment.js library:
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 the above example we use an UTC+1 time zone, i.e. we specify a 60 minute offset from the UTC reference time.
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:
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:
The complete message contents in our template are as below:
Note that our energy meter will send only temperature, HVAC power and total power data, but will not send the other attributes in the JSON object, which are defined only for internal use by the network simulator and are prefixed with “_$”.
We are now going to set up IBM Bluemix so that data coming from our simulated energy meter will be displayed graphically.
For information on how to set up IoT devices in IBM Bluemix you can refer to our article “Connecting to IBM Bluemix”. Once the basic set up is done, from the IBM Watson IoT Platform dashboard expand the left menu and click Boards:
Then click Device-Centric Analytics and 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 must be consistent with the MQTT topic in the simulator template, 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:
Now we are ready to start our 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 choosing a name, selecting 1 as number of clients, and choosing a message interval and a repetition count, then start the simulation.
As soon as the simulated device starts sending data, you can see this data visualized in IBM Bluemix:
IBM Bluemix provides a number of data analytics tools to help you monitor and make sense of IoT data coming from (real or simulated) devices. For example, it is possible to configure a rule that displays an alert and sends an e-mail when some conditions on the data received from a device are met. To illustrate this functionality, we will set up a rule that sends us an e-mail when the total power reported by our energy meter exceeds a configured threshold value.
In order for a rule to be defined for a given device, the corresponding device type must have an associated schema in IBM Bluemix: to define the schema, expand the left menu in the IBM Bluemix dashboard, then click Devices; in the devices screen, click Manage Schemas and then Add Schema:
Select your device type and click Next. In the following screen, we are going to define device properties whose values can be retrieved by an analytics rule; these properties correspond to the JSON attributes sent by our simulated energy meter. Since our message contents have only a top-level attribute, named “d”, and the remaining data are defined as children attributes of “d”, the first property that must be added to the schema is a “parent” property. Click Add Property, then give a name to the property, select “Parent” as data type, and write “d” in the property field:
Then, click OK and the property will appear in the list of properties for this schema. Now we have to define the properties containing the real data, i.e. temperature and power; according to the hierarchy of JSON objects in the MQTT message contents, these properties will be children of our parent property. To add a new child property, click on the symbol indicated by a red arrow in the following figure:
Then, in the property definition screen, insert the data for the property, making sure that the text in the Property field equals the name of the corresponding JSON attribute; for example, the following figure shows the definition of the “Total Power” attribute:
After the various properties have been defined, they will appear as children of the “d” property:
Click Finish to save the schema definition.
Once a schema has been defined, we can create a rule that uses the schema to retrieve data of interest from a device. From the IBM Watson IoT Platform dashboard, expand the left menu and click Rules, then in the rules page click Create Cloud Rule; in the Add new Cloud Rule screen, insert a name for your rule and select the type associated to our simulated device:
Then, in the rule definition we have to specify one or more conditions under which the rule is triggered, and one or more actions executed as a result of the rule being triggered; in our example, we define a single condition, which compares the total power with a threshold value of 6000 W:
Next, we are going to define an action: in the action definition dialog window, click Add Action; in the Edit Action window, insert a name for the action and select Send email as type:
Click Next, and in the next screen configure other details such as the list of recipients and whether you would like e-mails to contain device data; finally, click Finish to save the action definition.
To add the just created action to the rule, click on the action in the dialog window, then click OK to close the dialog window. The rule can now be saved by clicking on the Save button, activated by clicking on Activate, and then closed.
Now, with the above rule activated, every time our network simulator sends an MQTT message where the total power value is higher than 6000W, you will receive an e-mail, like in the example below:
In addition, an alert should appear in the IBM Watson IoT Platform dashboard, in the device-centric analytic screen where we previously added the data visualization graphs.