@guim31
So to start, you need to be able to retrieve the measured value in kWh directly in Node-Red
Once you have this value, we will record it in a Node-red database via a JS function
You then need to be able to update the value as often as possible. (In my case it’s updated every 0.01kWh)
For the part of retrieving data from your measuring equipment, that’s it.
Now let’s move on to Gladys, you need to create 1 MQTT device (In my case « inverter »)
In my device I have created 2 Features:
Type: Unknown
Name: Update 10 Min
Min: 0
Max: 1
Is it a sensor?: Deactivated
(This feature will allow Gladys to tell Node-Red to activate a function that we will create later)
Type: Energy consumed
Name: Energy Consumed (10 Min)
Min:0
Max: 100000
Is it a sensor?: Activated
(This feature will allow receiving values from Node-Red to Gladys)
Now that we have our 2 MQTT features, we will create our function in Node-Red
On the left is the « Update 10 Min » feature with the Gladys topic « MQTT to listen »
On the right is the « Energy Consumed (10 Min) » feature with the Gladys topic « MQTT to publish »
We have a JS function in the middle
if(global.get("Energie10Min") === undefined)
{
//If it doesn't exist, we create it with the last measured value (to initialize our first measurement)
global.set("Energie10Min", global.get("NewEnergie"));
}
//We calculate the difference between the last measured value and the new one and round to 2 decimal places
msg.payload = (global.get("NewEnergie") - global.get("Energie10Min")).toFixed(2);
//We record the new value as the old measured value
global.set("Energie10Min", global.get("NewEnergie"));
return msg;
Now all that’s left is to create the triggering scene in Gladys
If you want to have several intervals, you just need to create 2 new MQTT features in your module and duplicate this Node-Red part
Changing all the information except the name of the variable « NewEnergie » in the JS function because it corresponds to your automatically updated value in the first JS function created earlier
You can now display your values in the Gladys graphs
/!\ The first value received in Gladys will be 0, you will have to wait for the second reading to have the measurements
I created the following readings on my side:
10 Min
30 Min
1 Hour
1 Day
1 Week
1 Month
1 Year
And here are the results for
10 Min
30 Min
1 Hour
Let me know if it’s not all clear 