Fix invalid apparent and reactive power

This commit is contained in:
Theo Arends 2023-02-28 10:17:30 +01:00
parent cadab815ef
commit 5cdd9791f4
2 changed files with 12 additions and 0 deletions

View File

@ -1189,6 +1189,9 @@ void EnergyShow(bool json) {
if (isnan(apparent_power[i])) {
apparent_power[i] = Energy->voltage[i] * Energy->current[i];
}
else if (0 == Energy->current[i]) {
apparent_power[i] = 0;
}
if (apparent_power[i] < Energy->active_power[i]) { // Should be impossible
Energy->active_power[i] = apparent_power[i];
}
@ -1216,6 +1219,9 @@ void EnergyShow(bool json) {
reactive_power[i] = (float)(SqrtInt((uint32_t)(power_diff)));
}
}
else if (0 == Energy->current[i]) {
reactive_power[i] = 0;
}
}
}

View File

@ -1419,6 +1419,9 @@ void EnergyShow(bool json) {
if (isnan(apparent_power[i])) {
apparent_power[i] = Energy->voltage[i] * Energy->current[i];
}
else if (0 == Energy->current[i]) {
apparent_power[i] = 0;
}
if (apparent_power[i] < Energy->active_power[i]) { // Should be impossible
Energy->active_power[i] = apparent_power[i];
}
@ -1446,6 +1449,9 @@ void EnergyShow(bool json) {
reactive_power[i] = (float)(SqrtInt((uint32_t)(power_diff)));
}
}
else if (0 == Energy->current[i]) {
reactive_power[i] = 0;
}
}
}