# Measuring eletric power and eletric energy consumption

Hello,

I’m using an ACS712 and ESP8266 to obtain the values of eletric current (Amperes) of an eletric load, to monitor it on my cayenne dashboard.

I managed to send to cayenne dashboard the values of instant eletric power consumption, in W (Watts), using this documentation: Data types for Cayenne MQTT API
I’m using this function to do so:

CAYENNE_OUT(1)
{
Cayenne.virtualWrite(1, power, “pow”, “W”);
}
The values on cayenne dashboard are correct comparing to eletric load oficial caractheristics.

I want to have a graph, on my cayenne dashboard, of the eletric energy consumption, in Wh (Watts/hour). That graph will have the eletric energy consumption in the Y axis (Wh) and the time (hours or minutes or seconds) in the X axis. So, I tried this code, sending the power value in kW:

CAYENNE_OUT(1)
{
Cayenne.virtualWrite(1, power, “energy”, “kwh”);
}

And this is the result in cayenne dashboard:

Something is wrong, because the eletric load I used was of 1419 W (1,419 kW) during 5 seconds, then I used 2360 W (2,360 kW) load during 5 seconds… So the eletric energy consumption should be very low, (around 0,004 kWh) but the graph shows that I consumed around 3 KWh ?
Any opinions or problems in my logic?

Thank you.

First, W should lower case w

and are you converting power from watt to kilowatt in your code by dividing by 1000?
can you share the entire code you are using.

Corrected the lower case of w.
Yes, as commented in code below, I convert the power from Watts (W) to Kilowatts (kW):

#include <CayenneMQTTESP8266.h>

#define CAYENNE_PRINT Serial
#define CAYENNE_DEBUG
#define VIRTUAL_CHANNEL 1

// WiFi network info.
char ssid = “”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char clientID = “x”;

float power;
float energy;

void setup() {
Serial.begin(115200);
}

void loop() {
float output = 0;
int max1 = 0;
int max2 = 0;
int max3 = 0;
int average = 0;

for (int i = 0; i < 500; i++)
{
Serial.print(output);
Serial.println();
if (output > max1) {
max1 = output;
}
}
for (int i = 0; i < 500; i++)
{
Serial.print(output);
Serial.println();
if (output > max2) {
max2 = output;
}
}
for (int i = 0; i < 500; i++)
{
Serial.print(output);
Serial.println();
if (output > max3) {
max3 = output;
}
}
average = (max1 + max2 + max3) / 3;

Serial.println();
Serial.print(“Average=”);
Serial.print(average);
Serial.println();
power = (((average - 531) / 19.58) * 230); //conversion of output signal from ACS712, to current (Amperes), to power (W)
Serial.println();
Serial.print(“Power(W):”);
Serial.print(power);
Serial.println();

energy = power / 1000; //conversion of power in Watts (W), to power in kilowatts (kW)
Serial.print(“Power (KW):”);
Serial.print(energy);
Serial.println();
Cayenne.loop();
}

CAYENNE_OUT(1)
{
Cayenne.virtualWrite(1, power, “pow”, “w”);
}
CAYENNE_OUT(2)
{
Cayenne.virtualWrite(2, energy, “energy”, “kwh”);
}

so does it works?

This is the result of the graph of eletric energy consumpted:

A graph of eletric energy consumpted (kWh) must never decrease in value. It’s curve should always remain horizontal or longitudinal (always with same value of kWh or increasing, never decreasing).

The graph of eletric power is correct:

`energy = power / 1000;`
so when power will decrease will energy decrease or remain same?

The power variable is the value of instant eletric power consumpted by the load, in Watts.
For example, when I turn a eletric load of 1 kW eletric power during an hour, the graph of eletric energy consumpted will be a line with angle between 1º and 89º (depending on the time axis), that ends in the 1kWh value (of vertical kWh axis). When I turn off the eletric load, the graph of eletric energy consumpted will then be an horizontal line with the time axis, with the value of 1kWh. When I turn the eletric load it will happen the same as explained first.

What is the value i’m supposed to send to cayenne, to the “energy” variable? How did you configure it?

Maybe I’m explaining myself wrong.

Considering Power in kilowatts.
I know that eletric energy consumpted (in kWh) is: Energy(kWh)=Power(kW)*time(h)
With that time being the hours the eletric load is consuming eletricity.

I’m asking, is the instant eletric power value that I should send to the energy variable?

CAYENNE_OUT(2

{
Cayenne.virtualWrite(2, energy, “energy”, “kwh”);
}

Will the cayenne dashboard process that information, receiving instant eletric power and converting it to eletric energy consumpted (kWh) ?

Example of eletric energy consumption graph: Example of eletric power consumption graph: cayenne does not do any processing, it just show the data you sent to it. So if you are sending power, it will power value. If you are sending `energy = power / 1000;` then it will show `power value divide by 1000` so that is the reason why are you the same graph as power for the energy just scaled by 0.001

Interesting. So I will have to send the energy data already processed (calculated in amount and time) and graphically ready to the cayenne dashboard.

Thank you.