Gravio Blog
November 1, 2024

[Tutorial] Using Eniscope, an Energy Monitoring Device and Gravio to Measure and Log your Energy Consumption with MQTT.

Tutorial on how to use Gravio, MQTT, and Eniscope to build a simple Energy reporting and logging system without coding. Connect data points to Line for notifications and writing to a CSV file for logging.
[Tutorial] Using Eniscope, an Energy Monitoring Device and Gravio to Measure and Log your Energy Consumption with MQTT.

[Tutorial] Using Eniscope, an Energy Monitoring Device and Gravio to Measure and Log your Energy Consumption with MQTT.

Introduction

This tutorial will show you how you can use an existing or new energy monitoring device like Eniscope to log energy consumption at a cost effective rate without coding using MQTT and Gravio.

Approach

tldr; we will use Gravio and MQTT to integrate data from Eniscope such as power, voltage and other metrics and send the data through Line messaging platform and log the data in a csv file.

How Does It Work?

  1. Eniscope logs energy consumption data from various channels that the device is connected to
  2. Eniscope publishes data via MQTT to an MQTT Broker. (Settings to be set by Eniscope device)
  3. Gravio subscribes to topic and gets energy consumption data
  4. Gravio builds an Action to store data accordingly

Tutorial

Requirements

  • Gravio HubKit installed (available on Mac, Windows and Ubuntu)
  • Gravio Studio installed (available on macOS and Windows)
  • Eniscope Device with at least 1 channel connected (optional)
  • MQTT Broker (For this tutorial, I am using one from HiveMQ)

Steps

Part 1: Setting up Eniscope, Publishing Data to HiveMQ MQTT Broker and Subscribing to a Topic using HiveMQ Console.

Step 1:

Ensure that your Eniscope is set up properly and configure the data to be published to your MQTT Broker. Here is how it is supposed to look like in the portal:

*Disclaimer: Screenshots of Eniscope are taken from their official documentation

If the above image resolution is too low, please refer to the official documentation on Page 41 for the MQTT Setup instructions. Please remember to enter your topic and broker credentials so that Eniscope can publish the readings to the broker via MQTT.

Step 2:

Check that Eniscope energy data is being published to your MQTT Broker. For this example, I will be using a HiveMQ MQTT Broker to verify that data is coming through. Also, we will be using AI Generated in the same payload data structure provided by Eniscope to provide test data. Here’s an example of how the Eniscope payload should look like:

From this, we can use ChatGPT to create a sample payload which we will use the HiveMQ portal to publish.

*The reason for using AI generated data is because it is easier to visualize all connected channels with all the data coming through. But the concept remains the same, from publishing directly from Eniscope device, to an MQTT Broker.

Step 3:

Publish the test data using the HiveMQ console on the web. You should see the published data coming through to the subscribed topic in the same console.

Part 2: Subscribing to a MQTT Broker Topic with Gravio and Aggregating Energy Consumption Data

Step 1:

Launch Gravio Studio and connect to your Gravio HubKit (Gravio Node). If you need help in getting started, check out our video on how to get started with Gravio for free. Connect to the HiveMQ MQTT Broker in Gravio Studio.

Then, add the topic to the MQTT topic list in Gravio.

Step 2:

Create the Data Layer in Gravio Studio to start receiving data from the MQTT Topic.

Step 3:

View the integrated data from Eniscope in Gravio using the “Data Viewer” tab. Remember to publish the Test Data again from HiveMQ Console to send a new payload. If you have a connected Eniscope device, wait for the next publish from the device and you should see data streaming into Gravio.

Part 3: Build Energy Reporting Application

Step 1:

To build a simple energy logging and reporting application, we will use a few components that are made available out of the box with Gravio. In this case, we will use Line for reporting and CSV for logging of energy data.

*You can use any other method to log the data, for example, in Gravio, we have SQL components and you can write the values directly into the Database.

There should be 2 Actions to be built, 1 for logging energy data as it comes in and 1 more for reporting when there is an energy spike (for example, above a certain value or threshold)

Let us build the first Action, real-time energy reporting.

First, we need to decide on which components to use, in this case, we will need to filter for a specific value and then only send a message through Line if the value is above X.

Gravio Action Components Used:

  • Line Notify

Create the Energy Reporting Action in the Actions tab.

Step 2:

In the Energy Reporting Action, add a Line Notify component.

*You will need your Line Notify Token for this component, please get it from here.

Then, you can set the message you would like to be sent when you want to notify someone. In this example, we will be using Current (A) value.

Map and filter the data using JSONPath to only extract the Current(A) value.

You can use JSONPath("$.rtdata[?(@.I)].I", tv.Data) in this case.

Follow the pre-mapping set up according to the screenshots and your Action is ready.

Step 3:

At this point, you will need to create a Trigger so that Gravio knows when to run the Energy Reporting Action to publish and notify the real-time value of Current(A). Create a new Trigger and use an expression to filter for Current values that are out of the ordinary, in this case, we will use 6A as an example.

We will be using this expression tv.Data.rtdata[0].I > 6 .This means that the Trigger will only run the Energy Reporting Action if Current Value, I, is more than 6.

Then, you can map your Trigger to the Action you would like to run, in this case, Energy Reporting.

Step 4:

You can try it out now, wait for the next data packet and you will see your automation running live! You can try out the filter as well, change the threshold values higher or lower to see if the reporting works as expected.

Part 4: Build Energy Logging Application

Step 1:

The steps here will be similar to building the Energy Reporting Application. The only difference here is that we will be using the FileWrite component to write values and timestamp into a CSV file. Create an Action called Energy Logging.

Then, in the Action, add the FileWrite component as the first step. Set up the parameters accordingly, like in the screenshot below. Name your file where you want to log your values. 

In this case, we are using the file name “energylog.csv”

Here is the command used for the Pre-mappings

DateFormat(Now(), "02 Jan 06 15:04 MST") + "," + JSONPath("$.rtdata[?(@.I)].I", tv.Data) + "\r"

Step 2:

Create a Trigger for the Energy Logging action.

Select the Condition by mapping it to the MQTT Data layer that was set up earlier.

Then map it to the Energy Logging Action

Ensure both Triggers are turned on.

Step 3:

Both applications should be automated and running live now. Check the new Trigger and Action so that it is working as expected. After a few minutes or data points have been logged in Gravio, you can look for files that are stored within Gravio’s environment in the Actions page.

Download the “energylog.csv” file and open it.

Summary

It’s done! This tutorial shows you how to integrate data over MQTT specifically from an Eniscope device just by using pseudo data. The steps for integrating live data should be exactly the same.

This is also not limited to Eniscope but any data that can be published/subscribed using MQTT. Let us know if you are keen to deploy this or run into some problems while following this tutorial and we will be happy to help!

To get started with Gravio, you can follow our getting started for free guide here.

Latest Posts
[Tutorial] How to Set Up a Mosquitto MQTT Broker Securely — Using Client Certificates
Step by step guide how to secure MQTT Mosquitto Broker
Tuesday, August 20, 2024
Read More