Add restore power state when limiit restored

Add restore power state when limiit restored (#6340)
This commit is contained in:
Theo Arends 2019-09-03 22:22:36 +02:00
parent 8e4dd169f3
commit 1478f1624a
2 changed files with 14 additions and 2 deletions

View File

@ -598,6 +598,14 @@ void SetAllPower(uint8_t state, int source)
}
}
void RestoreAllPower(power_t power_set, int source)
{
if (power != power_set) {
SetDevicePower(power, source);
MqttPublishAllPowerState();
}
}
void MqttShowPWMState(void)
{
ResponseAppend_P(PSTR("\"" D_CMND_PWM "\":{"));

View File

@ -110,6 +110,8 @@ struct ENERGY {
bool max_current_flag = false;
#ifdef USE_ENERGY_POWER_LIMIT
power_t mp_last_power = 0;
power_t me_last_power = 0;
uint16_t mplh_counter = 0;
uint16_t mplw_counter = 0;
uint8_t mplr_counter = 0;
@ -317,6 +319,7 @@ void EnergyMarginCheck(void)
Response_P(PSTR("{\"" D_JSON_MAXPOWERREACHED "\":\"%d%s\"}"), energy_power_u, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
Energy.mp_last_power = power;
SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER);
if (!Energy.mplr_counter) {
Energy.mplr_counter = Settings.param[P_MAX_POWER_RETRY] +1;
@ -339,7 +342,7 @@ void EnergyMarginCheck(void)
if (Energy.mplr_counter) {
Response_P(PSTR("{\"" D_JSON_POWERMONITOR "\":\"%s\"}"), GetStateText(1));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_POWERMONITOR));
SetAllPower(POWER_ALL_ON, SRC_MAXPOWER);
RestoreAllPower(Energy.mp_last_power, SRC_MAXPOWER);
} else {
Response_P(PSTR("{\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0));
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
@ -357,7 +360,7 @@ void EnergyMarginCheck(void)
Energy.max_energy_state = 1;
Response_P(PSTR("{\"" D_JSON_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1));
MqttPublishPrefixTopic_P(RESULT_OR_STAT, PSTR(D_JSON_ENERGYMONITOR));
SetAllPower(POWER_ALL_ON, SRC_MAXENERGY);
RestoreAllPower(Energy.me_last_power, SRC_MAXENERGY);
}
else if ((1 == Energy.max_energy_state ) && (energy_daily_u >= Settings.energy_max_energy)) {
Energy.max_energy_state = 2;
@ -365,6 +368,7 @@ void EnergyMarginCheck(void)
Response_P(PSTR("{\"" D_JSON_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (Settings.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
MqttPublishPrefixTopic_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
Energy.me_last_power = power;
SetAllPower(POWER_ALL_OFF, SRC_MAXENERGY);
}
}