diff --git a/RELEASENOTES.md b/RELEASENOTES.md index aba4ced89..24e65e4b0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -104,4 +104,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add support for Thermostat control by arijav (#8212) - Add experimental basic support for Tasmota on ESP32 based on work by Jörg Schüler-Maroldt - Add automatic compression of Rules to achieve ~60% compression, added ``SetOption93 1`` to control caching of rules -- Add rule trigger ``#`` to trigger on any root value like ``on #loadavg<50 do power 2 endon`` after ``state`` command +- Add rule trigger at root level like ``on loadavg<50 do power 2 endon`` after ``state`` command diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index f02a4c320..a54809a68 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -7,7 +7,7 @@ - Add support for OpenTherm by Yuriy Sannikov (#8373) - Add support for Thermostat control by arijav (#8212) - Add automatic compression of Rules to achieve ~60% compression, added ``SetOption93 1`` to control caching of rules -- Add rule trigger ``#`` to trigger on any root value like ``on #loadavg<50 do power 2 endon`` after ``state`` command +- Add rule trigger at root level like ``on loadavg<50 do power 2 endon`` after ``state`` command - Change flash access removing support for any Core before 2.6.3 - Change HAss discovery by Federico Leoni (#8370) - Change default PWM Frequency to 977 Hz from 223 Hz diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index f790768b9..f2f01a8db 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -417,19 +417,20 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) char stemp[10]; // Step1: Analyse rule - int pos = rule.indexOf('#'); - if (pos == -1) { return false; } // No # sign in rule - - String rule_task = rule.substring(0, pos); // "INA219" or "SYSTEM" + String rule_expr = rule; // "TELE-INA219#CURRENT>0.100" if (Rules.teleperiod) { - int ppos = rule_task.indexOf("TELE-"); // "TELE-INA219" or "INA219" + int ppos = rule_expr.indexOf("TELE-"); // "TELE-INA219#CURRENT>0.100" or "INA219#CURRENT>0.100" if (ppos == -1) { return false; } // No pre-amble in rule - rule_task = rule.substring(5, pos); // "INA219" or "SYSTEM" + rule_expr = rule.substring(5); // "INA219#CURRENT>0.100" or "SYSTEM#BOOT" } - String rule_expr = rule.substring(pos +1); // "CURRENT>0.100" or "BOOT" or "%var1%" or "MINUTE|5" String rule_name, rule_param; - int8_t compareOperator = parseCompareExpression(rule_expr, rule_name, rule_param); //Parse the compare expression.Return operator and the left, right part of expression + int8_t compareOperator = parseCompareExpression(rule_expr, rule_name, rule_param); // Parse the compare expression.Return operator and the left, right part of expression + + // rule_name = "INA219#CURRENT" + // rule_param = "0.100" or "%VAR1%" + +//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: expr %s, name %s, param %s"), rule_expr.c_str(), rule_name.c_str(), rule_param.c_str()); char rule_svalue[80] = { 0 }; float rule_value = 0; @@ -477,11 +478,12 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) if (temp_value > -1) { rule_value = temp_value; } else { - rule_value = CharToFloat((char*)rule_svalue); // 0.1 - This saves 9k code over toFLoat()! + rule_value = CharToFloat((char*)rule_svalue); // 0.1 - This saves 9k code over toFLoat()! } } - // Step2: Search rule_task and rule_name + // Step2: Search rule_name + int pos; int rule_name_idx = 0; if ((pos = rule_name.indexOf("[")) > 0) { // "SUBTYPE1#CURRENT[1]" rule_name_idx = rule_name.substring(pos +1).toInt(); @@ -491,21 +493,10 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) rule_name = rule_name.substring(0, pos); // "SUBTYPE1#CURRENT" } -//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: Find Task %s, Name %s"), rule_task.c_str(), rule_name.c_str()); - StaticJsonBuffer<1024> jsonBuf; JsonObject &root = jsonBuf.parseObject(event); if (!root.success()) { return false; } // No valid JSON data - - JsonObject *obj; - if ((rule_task.length() == 0) || rule_task.startsWith("ROOT")) { // Support root level - obj = &root; - } else { - if (!root[rule_task].success()) { return false; } // No rule_task in JSON data - JsonObject &obj1 = root[rule_task]; - obj = &obj1; - } - + JsonObject *obj = &root; String subtype; uint32_t i = 0; while ((pos = rule_name.indexOf("#")) > 0) { // "SUBTYPE1#SUBTYPE2#CURRENT" @@ -524,8 +515,8 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule) str_value = (*obj)[rule_name]; // "CURRENT" } -//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: Task %s, Name %s, Value |%s|, TrigCnt %d, TrigSt %d, Source %s, Json %s"), -// rule_task.c_str(), rule_name.c_str(), rule_svalue, Rules.trigger_count[rule_set], bitRead(Rules.triggers[rule_set], Rules.trigger_count[rule_set]), event.c_str(), (str_value) ? str_value : "none"); +//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("RUL: Name %s, Value |%s|, TrigCnt %d, TrigSt %d, Source %s, Json %s"), +// rule_name.c_str(), rule_svalue, Rules.trigger_count[rule_set], bitRead(Rules.triggers[rule_set], Rules.trigger_count[rule_set]), event.c_str(), (str_value) ? str_value : "none"); Rules.event_value = str_value; // Prepare %value%