Fix Power off due to overtemp and/ot overload

This commit is contained in:
Theo Arends 2024-04-08 12:03:11 +02:00
parent 669bb582e0
commit 9cacf2f609
4 changed files with 25 additions and 21 deletions

View File

@ -371,7 +371,7 @@ enum TopicOptions { CMND, STAT, TELE, nu1, RESULT_OR_CMND, RESULT_OR_STAT, RESUL
enum UploadTypes { UPL_TASMOTA = 1, UPL_SETTINGS, UPL_EFM8BB1, UPL_TASMOTACLIENT, UPL_EFR32, UPL_SHD, UPL_CCL, UPL_UFSFILE };
enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP,
enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, POWER_OFF_FORCE,
POWER_OFF_NO_STATE = 8, POWER_ON_NO_STATE, POWER_TOGGLE_NO_STATE,
POWER_SHOW_STATE = 16 };
enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, POWER_RELEASE = 7,

View File

@ -373,11 +373,11 @@ void RestorePower(bool publish_power, uint32_t source)
}
}
void SetAllPower(uint32_t state, uint32_t source)
{
void SetAllPower(uint32_t state, uint32_t source) {
// state 0 = POWER_OFF = Relay Off
// state 1 = POWER_ON = Relay On (turn off after Settings->pulse_timer * 100 mSec if enabled)
// state 2 = POWER_TOGGLE = Toggle relay
// state 5 = POWER_OFF_FORCE = Relay Off even if locked
// state 8 = POWER_OFF_NO_STATE = Relay Off and no publishPowerState
// state 9 = POWER_ON_NO_STATE = Relay On and no publishPowerState
// state 10 = POWER_TOGGLE_NO_STATE = Toggle relay and no publishPowerState
@ -388,21 +388,25 @@ void SetAllPower(uint32_t state, uint32_t source)
state &= 3; // POWER_OFF, POWER_ON or POWER_TOGGLE
publish_power = false;
}
if ((state >= POWER_OFF) && (state <= POWER_TOGGLE)) {
if (((state >= POWER_OFF) && (state <= POWER_TOGGLE)) || (POWER_OFF_FORCE == state)) {
power_t all_on = POWER_MASK >> (POWER_SIZE - TasmotaGlobal.devices_present);
switch (state) {
case POWER_OFF:
// keep loocked bits and set all other to 0
TasmotaGlobal.power &= Settings->power_lock;
break;
// Keep locked bits and set all other to 0
TasmotaGlobal.power &= Settings->power_lock;
break;
case POWER_ON:
// Keep locked bits and set all other to 1
TasmotaGlobal.power = (TasmotaGlobal.power & Settings->power_lock) | (all_on & ~Settings->power_lock);
break;
// Keep locked bits and set all other to 1
TasmotaGlobal.power = (TasmotaGlobal.power & Settings->power_lock) | (all_on & ~Settings->power_lock);
break;
case POWER_TOGGLE:
// Keep locked bits and toggle all other
TasmotaGlobal.power ^= ~Settings->power_lock & all_on;
break;
// Keep locked bits and toggle all other
TasmotaGlobal.power ^= ~Settings->power_lock & all_on;
break;
case POWER_OFF_FORCE:
// Set all off even if locked on (Used by overtemp and overcurrent)
TasmotaGlobal.power = 0;
break;
}
SetDevicePower(TasmotaGlobal.power, source);
}

View File

@ -581,7 +581,7 @@ void EnergyMarginCheck(void) {
ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":%d}"), energy_power_u);
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER);
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
}
@ -608,7 +608,7 @@ void EnergyMarginCheck(void) {
ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0));
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER);
SetAllPower(POWER_OFF_FORCE, SRC_MAXPOWER);
}
}
}
@ -629,7 +629,7 @@ void EnergyMarginCheck(void) {
ResponseTime_P(PSTR(",\"" D_JSON_MAXENERGYREACHED "\":%3_f}"), &Energy->daily_sum);
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXENERGY);
SetAllPower(POWER_OFF_FORCE, SRC_MAXENERGY);
}
}
#endif // USE_ENERGY_POWER_LIMIT
@ -656,7 +656,7 @@ void EnergyEverySecond(void) {
AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Temperature %1_f"), &TasmotaGlobal.temperature_celsius);
SetAllPower(POWER_ALL_OFF, SRC_OVERTEMP);
SetAllPower(POWER_OFF_FORCE, SRC_OVERTEMP);
}
}

View File

@ -803,7 +803,7 @@ void EnergyMarginCheck(void) {
ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHED "\":%d}"), energy_power_u);
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER);
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
}
@ -830,7 +830,7 @@ void EnergyMarginCheck(void) {
ResponseTime_P(PSTR(",\"" D_JSON_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0));
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXPOWER);
SetAllPower(POWER_OFF_FORCE, SRC_MAXPOWER);
}
}
}
@ -851,7 +851,7 @@ void EnergyMarginCheck(void) {
ResponseTime_P(PSTR(",\"" D_JSON_MAXENERGYREACHED "\":%3_f}"), &Energy->daily_sum);
MqttPublishPrefixTopicRulesProcess_P(STAT, S_RSLT_WARNING);
EnergyMqttShow();
SetAllPower(POWER_ALL_OFF, SRC_MAXENERGY);
SetAllPower(POWER_OFF_FORCE, SRC_MAXENERGY);
}
}
EnergyFmtFree();
@ -876,7 +876,7 @@ void EnergyEverySecond(void) {
AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Temperature %1_f"), &TasmotaGlobal.temperature_celsius);
SetAllPower(POWER_ALL_OFF, SRC_OVERTEMP);
SetAllPower(POWER_OFF_FORCE, SRC_OVERTEMP);
}
}