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.
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.
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.
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.
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.
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.
Create the Data Layer in Gravio Studio to start receiving data from the MQTT Topic.
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.
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:
Create the Energy Reporting Action in the Actions tab.
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.
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.
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.
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"
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.
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.
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.