Add command `SetOption47 1..255`

Add command ``SetOption47 1..255`` to delay power on relay state in seconds reducing power surge
This commit is contained in:
Theo Arends 2022-11-03 17:26:54 +01:00
parent 438656dcdc
commit 4e9cfc7629
6 changed files with 61 additions and 5 deletions

View File

@ -9,7 +9,8 @@ All notable changes to this project will be documented in this file.
- Support for two phase power calibration using commands ``PowerSet2``, ``VoltageSet2`` and ``CurrentSet2``
- Support for NTAG2xx tags read and write on PN532 NFC reader (#16939)
- Berry ``bytes().reverse()`` method (#16977)
- Support for DMX ArtNet Led matrix animations
- ESP32 Support for DMX ArtNet Led matrix animations (#16984)
- Command ``SetOption47 1..255`` to delay power on relay state in seconds reducing power surge. ``SO47 1`` delays until network connected. ``SO47 2`` delays until mqtt connected
### Breaking Changed

View File

@ -109,6 +109,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
## Changelog v12.2.0.2
### Added
- Command ``SetOption47 1..255`` to delay power on relay state in seconds reducing power surge. ``SO47 1`` delays until network connected. ``SO47 2`` delays until mqtt connected
- Support for two phase power calibration using commands ``PowerSet2``, ``VoltageSet2`` and ``CurrentSet2``
- Command NeoPool ``NPFiltration 2`` toggle [#16859](https://github.com/arendst/Tasmota/issues/16859)
- Support for Shelly Pro 1/1PM and 2/2PM [#16773](https://github.com/arendst/Tasmota/issues/16773)
@ -118,6 +119,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
- Berry ``bytes().setbytes()`` method [#16892](https://github.com/arendst/Tasmota/issues/16892)
- Berry ``bytes().reverse()`` method [#16977](https://github.com/arendst/Tasmota/issues/16977)
- Zigbee router firmware for Sonoff ZBBridgePro [#16900](https://github.com/arendst/Tasmota/issues/16900)
- ESP32 Support for DMX ArtNet Led matrix animations [#16984](https://github.com/arendst/Tasmota/issues/16984)
### Breaking Changed

View File

@ -362,7 +362,7 @@ enum SO32_49Index { P_HOLD_TIME, // SetOption32 - (Button/Switch) K
P_IR_TOLERANCE, // SetOption44 - (IR) Base tolerance percentage for matching incoming IR messages (default 25, max 100)
P_BISTABLE_PULSE, // SetOption45 - (Bistable) Pulse time for two coil bistable latching relays (default 40)
P_POWER_ON_DELAY, // SetOption46 - (PowerOn) Add delay of 10 x value milliseconds at power on
P_SO47_FREE, // SetOption47
P_POWER_ON_DELAY2, // SetOption47 - (PowerOn) Add delay of value seconds at power on before activating relays
P_SO48_FREE, // SetOption48
P_SO49_FREE // SetOption49
}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49

View File

@ -253,6 +253,7 @@ struct TasmotaGlobal_t {
power_t blink_power; // Blink power state
power_t blink_powersave; // Blink start power save state
power_t blink_mask; // Blink relay active mask
power_t power_on_delay_state;
int serial_in_byte_counter; // Index in receive buffer
@ -333,6 +334,7 @@ struct TasmotaGlobal_t {
uint8_t last_source; // Last command source
uint8_t shutters_present; // Number of actual define shutters
uint8_t discovery_counter; // Delayed discovery counter
uint8_t power_on_delay; // Delay relay power on to reduce power surge (SetOption47)
#ifdef USE_PWM_DIMMER
uint8_t restore_powered_off_led_counter; // Seconds before powered-off LED (LEDLink) is restored
uint8_t pwm_dimmer_led_bri; // Adjusted brightness LED level

View File

@ -106,6 +106,11 @@ uint32_t ResetReason(void) {
return ESP_ResetInfoReason();
}
bool ResetReasonPowerOn(void) {
uint32_t reset_reason = ESP_ResetInfoReason();
return ((reset_reason == REASON_DEFAULT_RST) || (reset_reason == REASON_EXT_SYS_RST));
}
String GetResetReason(void) {
if (OsWatchBlockedLoop()) {
char buff[32];

View File

@ -240,6 +240,11 @@ void SetLatchingRelay(power_t lpower, uint32_t state) {
}
void SetDevicePower(power_t rpower, uint32_t source) {
if (TasmotaGlobal.power_on_delay) {
TasmotaGlobal.power_on_delay_state = rpower;
return;
}
ShowSource(source);
TasmotaGlobal.last_source = source;
@ -384,7 +389,7 @@ void SetPowerOnState(void)
SetDevicePower(1, SRC_RESTART);
} else {
power_t devices_mask = POWER_MASK >> (POWER_SIZE - TasmotaGlobal.devices_present);
if ((ResetReason() == REASON_DEFAULT_RST) || (ResetReason() == REASON_EXT_SYS_RST)) {
if (ResetReasonPowerOn()) {
switch (Settings->poweronstate) {
case POWER_ALL_OFF:
case POWER_ALL_OFF_PULSETIME_ON:
@ -422,7 +427,8 @@ void SetPowerOnState(void)
uint32_t port = 0;
for (uint32_t i = 0; i < TasmotaGlobal.devices_present; i++) {
#ifdef ESP8266
if (!Settings->flag3.no_power_feedback) { // SetOption63 - Don't scan relay power state at restart - #5594 and #5663
if (!Settings->flag3.no_power_feedback && // SetOption63 - Don't scan relay power state at restart - #5594 and #5663
!TasmotaGlobal.power_on_delay) { // SetOption47 - Delay switching relays to reduce power surge at power on
if ((port < MAX_RELAYS) && PinUsed(GPIO_REL1, port)) {
if (bitRead(TasmotaGlobal.rel_bistable, port)) {
port++; // Skip both bistable relays as always 0
@ -1056,6 +1062,29 @@ void PerformEverySecond(void)
#endif
}
if (TasmotaGlobal.power_on_delay) {
if (1 == Settings->param[P_POWER_ON_DELAY2]) { // SetOption47 1
// Allow relay power on once network is available
if (!TasmotaGlobal.global_state.network_down) {
TasmotaGlobal.power_on_delay = 0;
}
}
else if (2 == Settings->param[P_POWER_ON_DELAY2]) { // SetOption47 2
// Allow relay power on once mqtt is available
if (!TasmotaGlobal.global_state.mqtt_down) {
TasmotaGlobal.power_on_delay = 0;
}
}
else { // SetOption47 3..255
// Allow relay power on after x seconds
TasmotaGlobal.power_on_delay--;
}
if (!TasmotaGlobal.power_on_delay && TasmotaGlobal.power_on_delay_state) {
// Set relays according to last SetDevicePower() request
SetDevicePower(TasmotaGlobal.power_on_delay_state, SRC_RESTART);
}
}
if (TasmotaGlobal.mqtt_cmnd_blocked_reset) {
TasmotaGlobal.mqtt_cmnd_blocked_reset--;
if (!TasmotaGlobal.mqtt_cmnd_blocked_reset) {
@ -2046,6 +2075,19 @@ void GpioInit(void)
// AddLogBufferSize(LOG_LEVEL_DEBUG, (uint8_t*)TasmotaGlobal.gpio_pin, nitems(TasmotaGlobal.gpio_pin), sizeof(TasmotaGlobal.gpio_pin[0]));
if (ResetReasonPowerOn()) {
TasmotaGlobal.power_on_delay = Settings->param[P_POWER_ON_DELAY2]; // SetOption47 - Delay switching relays to reduce power surge at power on
if (TasmotaGlobal.power_on_delay) {
// This is the earliest possibility to disable relays connected to esp8266/esp32 gpios at power up to reduce power surge
for (uint32_t i = 0; i < MAX_RELAYS; i++) {
if (PinUsed(GPIO_REL1, i)) {
DigitalWrite(GPIO_REL1, i, bitRead(TasmotaGlobal.rel_inverted, i) ? 1 : 0); // Off
}
}
AddLog(LOG_LEVEL_DEBUG, PSTR("INI: SO47 Power off relays"));
}
}
analogWriteRange(Settings->pwm_range); // Default is 1023 (Arduino.h)
analogWriteFreq(Settings->pwm_frequency); // Default is 1000 (core_esp8266_wiring_pwm.c)
@ -2169,7 +2211,11 @@ void GpioInit(void)
}
}
delay(Settings->param[P_POWER_ON_DELAY] * 10); // SetOption46 - Allow Wemos D1 power to stabilize before starting I2C polling for devices powered locally
if (Settings->param[P_POWER_ON_DELAY]) { // SetOption46 - Allow Wemos D1 power to stabilize before starting I2C polling for devices powered locally
uint32_t init_delay = Settings->param[P_POWER_ON_DELAY] * 10;
AddLog(LOG_LEVEL_DEBUG, PSTR("INI: SO46 Wait %d msec"), init_delay);
delay(init_delay);
}
#ifdef USE_I2C
TasmotaGlobal.i2c_enabled = (PinUsed(GPIO_I2C_SCL) && PinUsed(GPIO_I2C_SDA));