From 9b537d81e0f09a40967bef732103127a79c82f7e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 3 Jul 2024 13:52:01 +0200 Subject: [PATCH] Fix energy maxpower retry count (#21695) --- .../tasmota_xdrv_driver/xdrv_03_energy.ino | 27 +++++++------- .../xdrv_03_esp32_energy.ino | 36 ++++++++----------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino index ce6341398..6c73cdbe2 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino @@ -572,13 +572,18 @@ void EnergyMarginCheck(void) { } Energy->mpl_hold_counter--; if (!Energy->mpl_hold_counter) { - ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":%d}"), energy_power_u); - MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING); - EnergyMqttShow(); - SetAllPower(POWER_OFF_FORCE, SRC_MAXPOWER); if (!Energy->mpl_retry_counter) { Energy->mpl_retry_counter = Settings->param[P_MAX_POWER_RETRY] +1; // SetOption33 - Max Power Retry count } + Energy->mpl_retry_counter--; + if (Energy->mpl_retry_counter) { + ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":%d}"), energy_power_u); + } else { + ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0)); + } + MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING); + EnergyMqttShow(); + SetAllPower(POWER_OFF_FORCE, SRC_MAXPOWER); Energy->mpl_window_counter = Settings->energy_max_power_limit_window; } } @@ -592,17 +597,9 @@ void EnergyMarginCheck(void) { Energy->mpl_window_counter--; } else { if (Energy->mpl_retry_counter) { - Energy->mpl_retry_counter--; - if (Energy->mpl_retry_counter) { - ResponseTime_P(PSTR(",\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1)); - MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR)); - RestorePower(true, SRC_MAXPOWER); - } else { - ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0)); - MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING); - EnergyMqttShow(); - SetAllPower(POWER_OFF_FORCE, SRC_MAXPOWER); - } + ResponseTime_P(PSTR(",\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1)); + MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR)); + RestorePower(true, SRC_MAXPOWER); } } } diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino index 1782ac2af..54bad4a41 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino @@ -835,14 +835,21 @@ void EnergyMarginCheck(void) { if (Energy->Settings.phase[phase].max_power_limit) { energy_power_u = (uint16_t)(Energy->active_power[phase]); bool power_on = (TasmotaGlobal.power & (1 << phase)); -// if (Energy->active_power[phase] > Energy->Settings.phase[phase].max_power_limit) { if (energy_power_u > Energy->Settings.phase[phase].max_power_limit) { if (!Energy->mpl_hold_counter[phase]) { Energy->mpl_hold_counter[phase] = Energy->Settings.phase[phase].max_power_limit_hold +1; } Energy->mpl_hold_counter[phase]--; if (!Energy->mpl_hold_counter[phase]) { - ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "%d\":%d}"), phase +1, energy_power_u); + if (!Energy->mpl_retry_counter[phase]) { + Energy->mpl_retry_counter[phase] = Settings->param[P_MAX_POWER_RETRY] +1; // SetOption33 - Max Power Retry count + } + Energy->mpl_retry_counter[phase]--; + if (Energy->mpl_retry_counter[phase]) { + ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "%d\":%d}"), phase +1, energy_power_u); + } else { + ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "%d\":\"%s\"}"), phase +1, GetStateText(0)); + } MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING); EnergyMqttShow(); if (set_all_power) { @@ -850,9 +857,6 @@ void EnergyMarginCheck(void) { } else { ExecuteCommandPower(phase +1, POWER_OFF_FORCE, SRC_MAXPOWER); } - if (!Energy->mpl_retry_counter[phase]) { - Energy->mpl_retry_counter[phase] = Settings->param[P_MAX_POWER_RETRY] +1; // SetOption33 - Max Power Retry count - } Energy->mpl_window_counter[phase] = Energy->Settings.phase[phase].max_power_limit_window; } } @@ -866,24 +870,12 @@ void EnergyMarginCheck(void) { Energy->mpl_window_counter[phase]--; } else { if (Energy->mpl_retry_counter[phase]) { - Energy->mpl_retry_counter[phase]--; - if (Energy->mpl_retry_counter[phase]) { - ResponseTime_P(PSTR(",\"" D_JSON_POWERMONITOR "%d\":\"%s\"}"), phase +1, GetStateText(1)); - MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR)); - if (set_all_power) { - RestorePower(true, SRC_MAXPOWER); - } else { - ExecuteCommandPower(phase +1, POWER_ON, SRC_MAXPOWER); - } + ResponseTime_P(PSTR(",\"" D_JSON_POWERMONITOR "%d\":\"%s\"}"), phase +1, GetStateText(1)); + MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR)); + if (set_all_power) { + RestorePower(true, SRC_MAXPOWER); } else { - ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "%d\":\"%s\"}"), phase +1, GetStateText(0)); - MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING); - EnergyMqttShow(); - if (set_all_power) { - SetAllPower(POWER_OFF_FORCE, SRC_MAXPOWER); - } else { - ExecuteCommandPower(phase +1, POWER_OFF_FORCE, SRC_MAXPOWER); - } + ExecuteCommandPower(phase +1, POWER_ON, SRC_MAXPOWER); } } }