From 674509a56e6226b7450acf5cb2c13a666c4ef7c4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 23 Apr 2021 10:59:33 +0200 Subject: [PATCH] Fix teleperiod rule handling regression Fix teleperiod rule handling regression from v9.3.1.2 (#11851) --- CHANGELOG.md | 5 ++++- RELEASENOTES.md | 3 ++- tasmota/tasmota.h | 2 +- tasmota/tasmota.ino | 1 - tasmota/xdrv_10_rules.ino | 12 +++++++++--- tasmota/xdrv_10_scripter.ino | 15 ++++++++------- tasmota/xdrv_interface.ino | 4 +--- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc431ed5..c710b9342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,12 @@ All notable changes to this project will be documented in this file. - Command ``Wifi 0/1`` for ESP8266 to turn wifi Off and On. When wifi is Off it is always returned On after a restart except for a wake-up from deepsleep (#11839) ### Changed -- Command ``Power`` should not reset pulsetime (#11805) - Zigbee refactored storage for device configuration and device last known data (#11838) +### Fixed +- Command ``Power`` should not reset pulsetime (#11805) +- Teleperiod rule handling regression from v9.3.1.2 (#11851) + ## [Released] ## [9.4.0] 20210422 diff --git a/RELEASENOTES.md b/RELEASENOTES.md index f67447224..aaabcbdf5 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -83,10 +83,11 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota ### Breaking Changed ### Changed -- Command ``Power`` should not reset pulsetime [#11805](https://github.com/arendst/Tasmota/issues/11805) - Zigbee refactored storage for device configuration and device last known data [#11838](https://github.com/arendst/Tasmota/issues/11838) ### Fixed +- Command ``Power`` should not reset pulsetime [#11805](https://github.com/arendst/Tasmota/issues/11805) +- Teleperiod rule handling regression from v9.3.1.2 [#11851](https://github.com/arendst/Tasmota/issues/11851) ### Noted - ESP32 single core **tasmota32solo1.bin** binary can only be uploaded using the GUI as OTA upload will trigger the watchdog timer \ No newline at end of file diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index e0ad51e8e..39df38727 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -311,7 +311,7 @@ enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_PIN_STATE, FUNC_MODULE_INIT, FU FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA, FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR, FUNC_ANY_KEY, FUNC_ENERGY_EVERY_SECOND, FUNC_ENERGY_RESET, - FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, + FUNC_RULES_PROCESS, FUNC_TELEPERIOD_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED, FUNC_WEB_ADD_BUTTON, FUNC_WEB_ADD_CONSOLE_BUTTON, FUNC_WEB_ADD_MANAGEMENT_BUTTON, FUNC_WEB_ADD_MAIN_BUTTON, FUNC_WEB_ADD_HANDLER, FUNC_SET_CHANNELS, FUNC_SET_SCHEME, FUNC_HOTPLUG_SCAN, FUNC_DEVICE_GROUP_ITEM }; diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index c8713eaea..b56b89a22 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -140,7 +140,6 @@ struct { int16_t save_data_counter; // Counter and flag for config save to Flash RulesBitfield rules_flag; // Rule state flags (16 bits) - bool rule_teleperiod; // Process rule based on teleperiod data using prefix TELE- bool serial_local; // Handle serial locally bool fallback_topic_flag; // Use Topic or FallbackTopic bool backlog_nodelay; // Execute all backlog commands with no delay diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index d4ac6a66e..b2692f6b0 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -174,6 +174,7 @@ struct RULES { uint16_t last_minute = 60; uint16_t vars_event = 0; // Bitmask supporting MAX_RULE_VARS bits uint16_t mems_event = 0; // Bitmask supporting MAX_RULE_MEMS bits + bool teleperiod = false; bool busy = false; bool no_execute = false; // Don't actually execute rule commands @@ -420,7 +421,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all // Step1: Analyse rule String rule_expr = rule; // "TELE-INA219#CURRENT>0.100" - if (TasmotaGlobal.rule_teleperiod) { + if (Rules.teleperiod) { int ppos = rule_expr.indexOf(F("TELE-")); // "TELE-INA219#CURRENT>0.100" or "INA219#CURRENT>0.100" if (ppos == -1) { return false; } // No pre-amble in rule rule_expr = rule.substring(5); // "INA219#CURRENT>0.100" or "SYSTEM#BOOT" @@ -433,7 +434,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all // rule_param = "0.100" or "%VAR1%" #ifdef DEBUG_RULES -// AddLog_P(LOG_LEVEL_DEBUG, PSTR("RUL-RM1: expr %s, name %s, param %s"), rule_expr.c_str(), rule_name.c_str(), rule_param.c_str()); + AddLog_P(LOG_LEVEL_DEBUG, PSTR("RUL-RM1: Teleperiod %d, Expr %s, Name %s, Param %s"), Rules.teleperiod, rule_expr.c_str(), rule_name.c_str(), rule_param.c_str()); #endif char rule_svalue[80] = { 0 }; @@ -852,7 +853,7 @@ void RulesInit(void) bitWrite(Settings.rule_once, i, 0); } } - TasmotaGlobal.rule_teleperiod = false; + Rules.teleperiod = false; } void RulesEvery50ms(void) @@ -2339,6 +2340,11 @@ bool Xdrv10(uint8_t function) case FUNC_RULES_PROCESS: result = RulesProcess(); break; + case FUNC_TELEPERIOD_RULES_PROCESS: + Rules.teleperiod = true; + result = RulesProcess(); + Rules.teleperiod = false; + break; case FUNC_SAVE_BEFORE_RESTART: RulesSaveBeforeRestart(); break; diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index 307b6f53d..e7c83435f 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -7886,13 +7886,14 @@ bool Xdrv10(uint8_t function) break; case FUNC_RULES_PROCESS: if (bitRead(Settings.rule_enabled, 0)) { - if (TasmotaGlobal.rule_teleperiod) { // Signal teleperiod event - if (TasmotaGlobal.mqtt_data[0]) { - Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data); - } - } else { - Run_Scripter(">E", 2, TasmotaGlobal.mqtt_data); - result = glob_script_mem.event_handeled; + Run_Scripter(">E", 2, TasmotaGlobal.mqtt_data); + result = glob_script_mem.event_handeled; + } + break; + case FUNC_TELEPERIOD_RULES_PROCESS: + if (bitRead(Settings.rule_enabled, 0)) { + if (TasmotaGlobal.mqtt_data[0]) { + Run_Scripter(">T", 2, TasmotaGlobal.mqtt_data); } } break; diff --git a/tasmota/xdrv_interface.ino b/tasmota/xdrv_interface.ino index 6dfab4f36..f508fd588 100644 --- a/tasmota/xdrv_interface.ino +++ b/tasmota/xdrv_interface.ino @@ -1080,14 +1080,12 @@ void XsnsDriverState(void) /*********************************************************************************************/ bool XdrvRulesProcess(bool teleperiod) { - TasmotaGlobal.rule_teleperiod = teleperiod; // Signal teleperiod event - bool rule_handled = XdrvCallDriver(10, FUNC_RULES_PROCESS); + bool rule_handled = XdrvCallDriver(10, (teleperiod) ? FUNC_TELEPERIOD_RULES_PROCESS : FUNC_RULES_PROCESS); #ifdef USE_BERRY // events are passed to both Rules engine AND Berry engine bool berry_handled = XdrvCallDriver(52, FUNC_RULES_PROCESS); rule_handled |= berry_handled; #endif - TasmotaGlobal.rule_teleperiod = false; return rule_handled; }