Time to cook: 60min
This recipe shows how you can use Node-RED to build a rich User Interface to monitor the energy consumption of an appliance. It builds further on the previous recipe ‘WiFi connected switch & energy monitoring’ which uses the Sonoff POW device to measure the energy consumption. Besides the Sonoff POW, you could consider using other devices such as the Z-wave Smart Plug to measure the energy consumption of equipment connected to the Plug.
The result of the recipe is a bar-graph visualization of the power consumption which is accessible via a browser and which fits nicely on a mobile device.
Sonoff POW R2
If you are not familiar with Node-Red, please read the Node-Red section in chapter 2 (Ingredients) first of the connected house 2.0 cookbook. To Visualize the energy consumption we are going to make use of a special node ‘Bar-chart-data’ which has been specially designed to handle meter readings and calculates the sum, min, max or average in a customizable time range.
The x-asses can be configured to show data in intervals of seconds, minutes, quarter-hour, hours, days, years and you can specify how many bars should be displayed.
Example: x-interval=hours, x-size=24 : 24 bars, each 1 hour. That means that the last 24 hours will be displayed
This formatted data can then be fed into a chart node which is part of the popular dashboard nodes.
The flow is quite straightforward, an example is given below.
The example shows 3 graphs. The first with a monthly view for the last 12 months. The second with a day view for the last 7 days and a third with an hourly view for the last 12 hrs.
The Building plan
Adding the ‘Bar-chart-data’ nodes
As a first step we are going to add the Bar-chart-data nodes to our Node-RED environment. The bar-chart-data node can be downloaded from the following location:
Login to your Node-RED environment
In the upper right menu, select manage palette
Click on the Install tab
in the search field, enter bar-chart-data
Select the node-red-contrib-dashboard-bar-chart-data node
When successful, the following node is added to the dashboard node collection:
Uploading the flow
next, upload the example flow:
The data is retrieved from an openhab2-in node. This node Listens to state changes of a selected openHAB Item. The item used from the Sonoff pow is the ‘Energy Total’
Note: Alternative, you could use an MQTT node to retrieve the data directly from the MQTT topic
The bar-chart configuration for the monthly representation is configured as follows:
Make sure the ‘Meter Reading’ setting is set to true and the Aggregated by setting to sum. The node will automatically device the readings and format the data usable for a bar-graph.
Next, the data is output to a chart node, which is configured as follows:
The result is shown in the image below:
The title on top is built using a text dashboard node.
This recipe demonstrates how you can build an energy consumption graph using Node-RED and visualise the energy consumption on an hourly, daily and monthly basis. By combining the graphs one can follow the trend of the energy consumption for a certain home-appliance.
In the example above, the Sonoff is used to measure the energy consumption of a fridge.