Charts - Show cumulative value by Day / Week / Month / Year

Hello :slight_smile:

I am proposing a feature for graphs.

The most concrete case I have in mind concerns electricity or water consumption.

Currently, a sensor retrieves all real-time values and transmits them to Gladys, which stores them in the database to generate the graph.

However, currently, if you display the graph in days, weeks, months, etc., you get an average of what is sent in real time each time.

The purpose of my request would be that when you configure a graph, you could have an option (enable or not) to choose to display the sum of the values over a configured period (days/week/month/year)

This would allow for a graph configured in « sum per week Â» to display the total consumption per week in the graph and no longer the average of the real-time values.

I don’t know if that’s very clear ^^

Thanks in advance if it can be done :wink:

For me, your request is very clear :slight_smile: because I encounter the same case as you with my electricity consumption/production.
On the other hand, I have no idea how this can be done, as it seems complex to me: I imagine that it would be necessary to retrieve the consumption data at fairly high frequencies (every minute?) to then make the calculation and cumulate them over 24 hours, then a week, then a month… if it is feasible, it’s great, but I am afraid that it is a data factory!

Still, I would really like to have this functionality, I vote for it! :wink:

In fact, it depends, because in my case, the consumption I measure is already in kWh.

I just have to take a measurement every 30 minutes, for example, and I retrieve the kWh consumed over the last 30 minutes, then I reset my meter and repeat.

This principle will therefore work in the same way if you take a measurement every minute or every 24 hours.

PS: I already have an idea of how to set this up with MQTT / Node-Red, I will test it and let you know.

With pleasure!

@guim31 I managed to do exactly what I wanted!

As soon as I have time, I’ll explain everything to you :smiley:

That’s great! I’m very interested! :wink:

This way, I’ll have in Gladys a similar set of features to what I have from my Solaredge app (solar panels) but that I can’t retrieve via the API!! :slight_smile:

@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 :wink:

It looks nice on a 24-hour display if you show everything at the same time ^^

The demand for Gladys without going through NodeRed also seems very relevant to me, I have the same need :blush:

Hi @Checconio :slight_smile:

I developed this feature here:

I think this meets the need!

Hello :slight_smile:

Thank you for the information, indeed it opens up many possibilities!

This new feature is available in Gladys Assistant 4.58: