From ca09594c24fa36a71399f68b6302615006733e69 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Fri, 1 Jan 2021 21:13:22 +0100 Subject: [PATCH 1/2] RuleTimer0 applies to all RuleTimers --- tasmota/xdrv_10_rules.ino | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 8d8fefc13..0142b9a09 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -2123,21 +2123,29 @@ void CmndRule(void) void CmndRuleTimer(void) { - if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_TIMERS)) { - if (XdrvMailbox.data_len > 0) { -#ifdef USE_EXPRESSION - float timer_set = evaluateExpression(XdrvMailbox.data, XdrvMailbox.data_len); - Rules.timer[XdrvMailbox.index -1] = (timer_set > 0) ? millis() + (1000 * timer_set) : 0; -#else - Rules.timer[XdrvMailbox.index -1] = (XdrvMailbox.payload > 0) ? millis() + (1000 * XdrvMailbox.payload) : 0; -#endif // USE_EXPRESSION - } - ResponseClear(); - for (uint32_t i = 0; i < MAX_RULE_TIMERS; i++) { - ResponseAppend_P(PSTR("%c\"T%d\":%d"), (i) ? ',' : '{', i +1, (Rules.timer[i]) ? (Rules.timer[i] - millis()) / 1000 : 0); - } - ResponseJsonEnd(); + if (XdrvMailbox.index > MAX_RULE_TIMERS) + return; + int i = XdrvMailbox.index, max_i = XdrvMailbox.index; + if (0 == i) { + i = 1; + max_i = MAX_RULE_TIMERS; } +#ifdef USE_EXPRESSION + float timer_set = evaluateExpression(XdrvMailbox.data, XdrvMailbox.data_len); + timer_set = (timer_set > 0) ? millis() + (1000 * timer_set) : 0; +#else + unsigned long timer_set = (XdrvMailbox.payload > 0) ? millis() + (1000 * XdrvMailbox.payload) : 0; +#endif // USE_EXPRESSION + if (XdrvMailbox.data_len > 0) { + for ( ; i <= max_i ; ++i ) { + Rules.timer[i -1] = timer_set; + } + } + ResponseClear(); + for (i = 0; i < MAX_RULE_TIMERS; i++) { + ResponseAppend_P(PSTR("%c\"T%d\":%d"), (i) ? ',' : '{', i +1, (Rules.timer[i]) ? (Rules.timer[i] - millis()) / 1000 : 0); + } + ResponseJsonEnd(); } void CmndEvent(void) From 5bb682b7e7b9f392a7b3482ee332c17c2e7f4474 Mon Sep 17 00:00:00 2001 From: Barbudor Date: Sat, 2 Jan 2021 18:47:03 +0100 Subject: [PATCH 2/2] insure ruletimers always stops at 0 --- tasmota/xdrv_10_rules.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 0142b9a09..2d0caed1d 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -974,9 +974,8 @@ void RulesEvery100ms(void) void RulesEverySecond(void) { + char json_event[120]; if (Settings.rule_enabled && !Rules.busy) { // Any rule enabled - char json_event[120]; - if (RtcTime.valid) { if ((TasmotaGlobal.uptime > 60) && (RtcTime.minute != Rules.last_minute)) { // Execute from one minute after restart every minute only once Rules.last_minute = RtcTime.minute; @@ -984,10 +983,12 @@ void RulesEverySecond(void) RulesProcessEvent(json_event); } } - for (uint32_t i = 0; i < MAX_RULE_TIMERS; i++) { - if (Rules.timer[i] != 0L) { // Timer active? - if (TimeReached(Rules.timer[i])) { // Timer finished? - Rules.timer[i] = 0L; // Turn off this timer + } + for (uint32_t i = 0; i < MAX_RULE_TIMERS; i++) { + if (Rules.timer[i] != 0L) { // Timer active? + if (TimeReached(Rules.timer[i])) { // Timer finished? + Rules.timer[i] = 0L; // Turn off this timer + if (Settings.rule_enabled && !Rules.busy) { // Any rule enabled snprintf_P(json_event, sizeof(json_event), PSTR("{\"Rules\":{\"Timer\":%d}}"), i +1); RulesProcessEvent(json_event); }