From 1fd8de676259729a413e9bce4d4b766fe23a13df Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:47:55 +0200 Subject: [PATCH] Update energy structure --- .../tasmota_xdrv_driver/xdrv_03_energy.ino | 36 +++++++++---------- .../xdrv_03_esp32_energy.ino | 36 +++++++++---------- .../xdrv_52_3_berry_energy.ino | 20 +++++------ 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino index cc364876f..d5fe43c4f 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino @@ -131,9 +131,9 @@ typedef struct { bool max_current_flag; #ifdef USE_ENERGY_POWER_LIMIT - uint16_t mplh_counter; - uint16_t mplw_counter; - uint8_t mplr_counter; + uint16_t mpl_hold_counter; + uint16_t mpl_window_counter; + uint8_t mpl_retry_counter; uint8_t max_energy_state; #endif // USE_ENERGY_POWER_LIMIT #endif // USE_ENERGY_MARGIN_DETECTION @@ -567,34 +567,34 @@ void EnergyMarginCheck(void) { // Max Power if (Settings->energy_max_power_limit) { if (Energy->active_power[0] > Settings->energy_max_power_limit) { - if (!Energy->mplh_counter) { - Energy->mplh_counter = Settings->energy_max_power_limit_hold; + if (!Energy->mpl_hold_counter) { + Energy->mpl_hold_counter = Settings->energy_max_power_limit_hold; } else { - Energy->mplh_counter--; - if (!Energy->mplh_counter) { + 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->mplr_counter) { - Energy->mplr_counter = Settings->param[P_MAX_POWER_RETRY] +1; // SetOption33 - Max Power Retry count + if (!Energy->mpl_retry_counter) { + Energy->mpl_retry_counter = Settings->param[P_MAX_POWER_RETRY] +1; // SetOption33 - Max Power Retry count } - Energy->mplw_counter = Settings->energy_max_power_limit_window; + Energy->mpl_window_counter = Settings->energy_max_power_limit_window; } } } else if (TasmotaGlobal.power && (energy_power_u <= Settings->energy_max_power_limit)) { - Energy->mplh_counter = 0; - Energy->mplr_counter = 0; - Energy->mplw_counter = 0; + Energy->mpl_hold_counter = 0; + Energy->mpl_retry_counter = 0; + Energy->mpl_window_counter = 0; } if (!TasmotaGlobal.power) { - if (Energy->mplw_counter) { - Energy->mplw_counter--; + if (Energy->mpl_window_counter) { + Energy->mpl_window_counter--; } else { - if (Energy->mplr_counter) { - Energy->mplr_counter--; - if (Energy->mplr_counter) { + 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); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino index 4c51b043c..1782ac2af 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_esp32_energy.ino @@ -181,8 +181,8 @@ typedef struct { float daily_sum_export_balanced; // 123.123 kWh uint16_t power_history[ENERGY_MAX_PHASES][3]; - uint16_t mplh_counter[ENERGY_MAX_PHASES]; - uint16_t mplw_counter[ENERGY_MAX_PHASES]; + uint16_t mpl_hold_counter[ENERGY_MAX_PHASES]; + uint16_t mpl_window_counter[ENERGY_MAX_PHASES]; uint8_t data_valid[ENERGY_MAX_PHASES]; uint8_t phase_count; // Number of phases active @@ -190,7 +190,7 @@ typedef struct { uint8_t command_code; uint8_t power_steady_counter; // Allow for power on stabilization uint8_t margin_stable; - uint8_t mplr_counter[ENERGY_MAX_PHASES]; + uint8_t mpl_retry_counter[ENERGY_MAX_PHASES]; uint8_t max_energy_state[ENERGY_MAX_PHASES]; uint8_t hour; @@ -837,11 +837,11 @@ void EnergyMarginCheck(void) { 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->mplh_counter[phase]) { - Energy->mplh_counter[phase] = Energy->Settings.phase[phase].max_power_limit_hold +1; + if (!Energy->mpl_hold_counter[phase]) { + Energy->mpl_hold_counter[phase] = Energy->Settings.phase[phase].max_power_limit_hold +1; } - Energy->mplh_counter[phase]--; - if (!Energy->mplh_counter[phase]) { + Energy->mpl_hold_counter[phase]--; + if (!Energy->mpl_hold_counter[phase]) { ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "%d\":%d}"), phase +1, energy_power_u); MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING); EnergyMqttShow(); @@ -850,24 +850,24 @@ void EnergyMarginCheck(void) { } else { ExecuteCommandPower(phase +1, POWER_OFF_FORCE, SRC_MAXPOWER); } - if (!Energy->mplr_counter[phase]) { - Energy->mplr_counter[phase] = Settings->param[P_MAX_POWER_RETRY] +1; // SetOption33 - Max Power Retry count + if (!Energy->mpl_retry_counter[phase]) { + Energy->mpl_retry_counter[phase] = Settings->param[P_MAX_POWER_RETRY] +1; // SetOption33 - Max Power Retry count } - Energy->mplw_counter[phase] = Energy->Settings.phase[phase].max_power_limit_window; + Energy->mpl_window_counter[phase] = Energy->Settings.phase[phase].max_power_limit_window; } } else if (power_on && (energy_power_u <= Energy->Settings.phase[phase].max_power_limit)) { - Energy->mplh_counter[phase] = 0; - Energy->mplr_counter[phase] = 0; - Energy->mplw_counter[phase] = 0; + Energy->mpl_hold_counter[phase] = 0; + Energy->mpl_retry_counter[phase] = 0; + Energy->mpl_window_counter[phase] = 0; } if (!power_on) { - if (Energy->mplw_counter[phase]) { - Energy->mplw_counter[phase]--; + if (Energy->mpl_window_counter[phase]) { + Energy->mpl_window_counter[phase]--; } else { - if (Energy->mplr_counter[phase]) { - Energy->mplr_counter[phase]--; - if (Energy->mplr_counter[phase]) { + 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) { diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino index 6622f76f1..874de687d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_energy.ino @@ -83,16 +83,16 @@ extern "C" { { "import_active", offsetof(tEnergy, import_active[0]), 0, 0, ctypes_float, 0 }, { "import_active_2", offsetof(tEnergy, import_active[1]), 0, 0, ctypes_float, 0 }, { "import_active_3", offsetof(tEnergy, import_active[2]), 0, 0, ctypes_float, 0 }, - { "max_current_flag", offsetof(tEnergy, max_current_flag), 0, 0, ctypes_u8, 0 }, - { "max_energy_state", offsetof(tEnergy, max_energy_state), 0, 0, ctypes_u8, 0 }, - { "max_power_flag", offsetof(tEnergy, max_power_flag), 0, 0, ctypes_u8, 0 }, - { "max_voltage_flag", offsetof(tEnergy, max_voltage_flag), 0, 0, ctypes_u8, 0 }, - { "min_current_flag", offsetof(tEnergy, min_current_flag), 0, 0, ctypes_u8, 0 }, - { "min_power_flag", offsetof(tEnergy, min_power_flag), 0, 0, ctypes_u8, 0 }, - { "min_voltage_flag", offsetof(tEnergy, min_voltage_flag), 0, 0, ctypes_u8, 0 }, - { "mplh_counter", offsetof(tEnergy, mplh_counter), 0, 0, ctypes_u16, 0 }, - { "mplr_counter", offsetof(tEnergy, mplr_counter), 0, 0, ctypes_u8, 0 }, - { "mplw_counter", offsetof(tEnergy, mplw_counter), 0, 0, ctypes_u16, 0 }, + { "max_current_flag", offsetof(tEnergy, max_current_flag[0]), 0, 0, ctypes_u8, 0 }, + { "max_energy_state", offsetof(tEnergy, max_energy_state[0]), 0, 0, ctypes_u8, 0 }, + { "max_power_flag", offsetof(tEnergy, max_power_flag[0]), 0, 0, ctypes_u8, 0 }, + { "max_voltage_flag", offsetof(tEnergy, max_voltage_flag[0]), 0, 0, ctypes_u8, 0 }, + { "min_current_flag", offsetof(tEnergy, min_current_flag[0]), 0, 0, ctypes_u8, 0 }, + { "min_power_flag", offsetof(tEnergy, min_power_flag[0]), 0, 0, ctypes_u8, 0 }, + { "min_voltage_flag", offsetof(tEnergy, min_voltage_flag[0]), 0, 0, ctypes_u8, 0 }, + { "mpl_hold_counter", offsetof(tEnergy, mpl_hold_counter[0]), 0, 0, ctypes_u16, 0 }, + { "mpl_retry_counter", offsetof(tEnergy, mpl_retry_counter[0]), 0, 0, ctypes_u8, 0 }, + { "mpl_window_counter", offsetof(tEnergy, mpl_window_counter[0]), 0, 0, ctypes_u16, 0 }, { "period", offsetof(tEnergy, period_kWh[0]), 0, 0, ctypes_float, 0 }, { "period_2", offsetof(tEnergy, period_kWh[1]), 0, 0, ctypes_float, 0 }, { "period_3", offsetof(tEnergy, period_kWh[2]), 0, 0, ctypes_float, 0 },