From 4e9cfc762929d34fe1d12588ff876ae09fd8da35 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 3 Nov 2022 17:26:54 +0100 Subject: [PATCH] Add command ``SetOption47 1..255`` Add command ``SetOption47 1..255`` to delay power on relay state in seconds reducing power surge --- CHANGELOG.md | 3 +- RELEASENOTES.md | 2 + tasmota/include/tasmota.h | 2 +- tasmota/tasmota.ino | 2 + tasmota/tasmota_support/support.ino | 5 ++ tasmota/tasmota_support/support_tasmota.ino | 52 +++++++++++++++++++-- 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ac716257..ac4a43954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/RELEASENOTES.md b/RELEASENOTES.md index ab0e97a8a..e582f6c68 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -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 diff --git a/tasmota/include/tasmota.h b/tasmota/include/tasmota.h index 3dee90dad..a78a5edb1 100644 --- a/tasmota/include/tasmota.h +++ b/tasmota/include/tasmota.h @@ -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 diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index c0652c563..f8cebb836 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -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 diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index f082a2206..2e1e77dd0 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -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]; diff --git a/tasmota/tasmota_support/support_tasmota.ino b/tasmota/tasmota_support/support_tasmota.ino index b51856b4b..a2a9ba8bf 100644 --- a/tasmota/tasmota_support/support_tasmota.ino +++ b/tasmota/tasmota_support/support_tasmota.ino @@ -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));