Is the energy consumption calculation wrong? Inconsistent?

Hello everyone,

I would need a bit of help with monitoring energy consumption.

Currently, I directly read the electricity consumption drawn from the grid in kW from the house’s electricity meter and transmit this value to Gladys with four decimal places. I have created a corresponding virtual device there, equipped with energy monitoring functions, defined the electricity rate and synchronized everything.

So: Node-RED provides, via a query, the current consumption in kW (for example 0.345 kW) and transmits this value every 15 minutes to Gladys. However, the calculation there seems completely wrong. For example, yesterday I had a consumption of around 3.75 kW. Gladys claims it was 15.69 kW… How can these huge differences be explained?

Hello @ruegerth,

Thanks for this detailed feedback, it will help us understand the situation better :slightly_smiling_face:

I think the calculation isn’t wrong, but the data sent is not what Gladys expects. There are two concepts to clearly distinguish:

  • kW = an instantaneous power (what you’re consuming at time T)
  • kWh = an energy (a power over a duration)

Your meter displays 0.345 kW: this is a power, not a consumption.

How Gladys calculates consumption

Gladys’ energy monitoring is based solely on « Index » type features (the cumulative index of your meter, in kWh, which only increases). Every 30 minutes, Gladys calculates the difference between successive index readings to determine the consumption for the period, then applies your rate.

« Power » type features are never used for this calculation; they are only used to display a curve.

Therefore, if the instantaneous power is sent in an « Index » or « Energy » type feature, Gladys calculates the difference between two powers and adds all positive variations. Example over a day:

0.3 → 1.2 → 0.4 → 2.1 → 0.5 …

Gladys counts +0.9, +1.7, etc. (drops are ignored, they are interpreted as a meter reset). You quickly get a total 3 to 5 times too large — which matches your 15.69 instead of 3.75.

Second detail: the unit kW is not an energy unit for Gladys (only Wh, kWh, and MWh are converted). A feature declared in kW is therefore taken as is as kWh at the time of cost calculation, which also distorts the rate.

Can you confirm?

In your device, what is the exact type of the feature fed by Node-RED (« Index », « Energy » or « Power ») and what unit is selected? A screenshot of the device in Gladys would help validate my hypothesis.

How to fix it

Ideal solution: send Gladys the cumulative index of your meter in kWh (the total that only increases, not the power), in an « Index » type feature with the unit kWh. There, a transmission every 15 minutes is perfectly sufficient, and the calculation will be accurate.

If your reading only gives you the instantaneous power: you need to build the index yourself in Node-RED by integrating the power over time. A function node before sending to Gladys:

const now = Date.now();
const powerKw = Number(msg.payload);              // instantaneous power in kW
const last = context.get('last');

if (!last) {
  context.set('last', { t: now, power: powerKw, index: 0 });
  return null;                                     // waiting for the 2nd reading
}

const deltaHours = (now - last.t) / 3600000;
const index = last.index + last.power * deltaHours; // cumulative kWh

context.set('last', { t: now, power: powerKw, index });
msg.payload = Number(index.toFixed(4));
return msg;

Two precautions:

  • use a persistent context (file storage in Node-RED), otherwise the index resets to zero on each restart;
  • with a reading every 15 minutes, we assume that the power remained constant throughout the interval: this is very approximate. If you go through this method, sample rather every minute (or 10-30 s), the precision will be much better. That’s also why the meter index remains the best source.

Once the correction is made

  1. Delete the erroneous history of the concerned feature (or create a clean feature);
  2. Go to Energy Tracking → Settings and launch « Recalculate Consumption », then « Calculate Cost from the Beginning ». You can follow the progress in the background tasks.

Let me know what the type and unit of your feature are, we’ll refine if needed!

A big thank you for your quick help.
If only I had paid better attention in physics class.
I can always start over from scratch, I’ve deleted everything for now.
On my electricity meter (in Germany, the energy supplier’s delivery point), I can view the reading to the second.
In Node-RED, I now query this meter every 15 minutes and send the data to Gladys via MQTT. Here’s what it looks like:

Translated with DeepL.com (free version)

I set up a virtual device in Gladys, I retrieve the MQTT topic and I set up energy consumption monitoring from there. Let’s see… I hope (for me and for you) to have correctly understood the difference between energy and power. Regards, Thomas

Sorry, I forgot… Here’s how the data is displayed in Gladys. For now, it’s like this, then every 15 minutes:

Awesome, is everything working now? :slight_smile:

Yes, thank you again (P.S.: Deep L is more powerful and more accurate for translation :wink: )

For your information, I don’t know if you speak English, but the forum automatically translates messages into this language.

If one day we have many German users, I could enable German translation! (But I pay for the AI translation requests, so we need a critical mass of users :smiley: )