I recently revised my hot water control to use JSY-MK-354 energy module to measure the supply power for controlling when to turn the hot water on/off to use the excess solar power.
I also calculate the daily electicity cost based on the Import / Export kWh.
However I found that the JSY-MK-354 module was grossly in-accurate.
The report on testing is here
Fortunately there is a simple software fix. Just integate the instaneous power and accumulate the Import / Export kWh in your software.
A 2sec sampling rate proved to accurate to better than 1.5% when compared to the electricity supply company's meter.
The code is
void integrate(float Power_W) {
static unsigned long lastTime_ms = 0;
unsigned long currentTime_ms = millis();
if (lastTime_ms > 0) { // Skip first reading
unsigned long deltaTime_ms = currentTime_ms - lastTime_ms;
if (deltatTime_ms < 6000) { // not a too large gap between measurements
float deltaTime_hrs = (float)deltaTime_ms / (3600.0 * 1000.0);
float power_kW = (float)Power_W / 1000.0; // power in kW
float energy_kWh = power_kW * deltaTime_hrs; // kWh for this time interval
// Update daily accumulators based on whether importing or exporting
if (power_kW >= 0) { // Importing
dailyImport_kWh += energy_kWh;
} else { // Exporting (power_kW is negative)
dailyExport_kWh -= energy_kWh; // Store as positive value
}
}
}
lastTime_ms = currentTime_ms;
}
This is a very basic integration, but the results show it is sufficient.