From 0c5f67709a0677cfaae44553fb00bee3db960da3 Mon Sep 17 00:00:00 2001 From: barbudor Date: Fri, 25 Mar 2022 22:28:05 +0100 Subject: [PATCH 1/2] fix %timerx% variable for negative values --- tasmota/xdrv_10_rules.ino | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 2b26107a7..53774d999 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -477,7 +477,11 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all if ((index > 0) && (index <= MAX_TIMERS)) { snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), index); if (rule_param.startsWith(stemp)) { - rule_param = String(Settings->timer[index -1].time); + int32_t timer = Settings->timer[index -1].time; + if (Settings->timer[index -1].mode && (timer >= 12*60)) { + timer = -(timer - (12*60)); + } + rule_param = String(timer); } } } @@ -796,7 +800,11 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved) #if defined(USE_TIMERS) for (uint32_t i = 0; i < MAX_TIMERS; i++) { snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1); - RulesVarReplace(commands, stemp, String(Settings->timer[i].time)); + int32_t timer = Settings->timer[i].time; + if (Settings->timer[i].mode && (timer >= 12*60)) { + timer = -(timer - 12*60); + } + RulesVarReplace(commands, stemp, String(timer)); } #if defined(USE_SUNRISE) RulesVarReplace(commands, F("%SUNRISE%"), String(SunMinutes(0))); From 3b10e0ef5c2ad2af53fa2c928d34e92fc44e79f9 Mon Sep 17 00:00:00 2001 From: barbudor Date: Sat, 26 Mar 2022 14:10:08 +0100 Subject: [PATCH 2/2] timerx returns absolute time of day 0:00 to 23:59 --- tasmota/xdrv_09_timers.ino | 16 ++++++++++++++++ tasmota/xdrv_10_rules.ino | 12 ++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tasmota/xdrv_09_timers.ino b/tasmota/xdrv_09_timers.ino index 44a164989..bde181967 100644 --- a/tasmota/xdrv_09_timers.ino +++ b/tasmota/xdrv_09_timers.ino @@ -235,6 +235,22 @@ uint16_t SunMinutes(uint32_t dawn) #endif // USE_SUNRISE +uint16_t TimerGetTimeOfDay(uint8_t index) +{ + Timer xtimer = Settings->timer[index]; + int16_t xtime = xtimer.time; +#ifdef USE_SUNRISE + if (xtimer.mode) { + if (xtime >= 12*60) xtime = 12*60 - xtime; + xtime += (int16_t)SunMinutes(xtimer.mode-1); + if (xtime < 0) xtime += 24*60; + if (xtime >= 24*60) xtime -= 24*60; + } +#endif +return xtime; +} + + /*******************************************************************************************/ void TimerSetRandomWindow(uint32_t index) diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index 53774d999..152824fd3 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -477,11 +477,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all if ((index > 0) && (index <= MAX_TIMERS)) { snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), index); if (rule_param.startsWith(stemp)) { - int32_t timer = Settings->timer[index -1].time; - if (Settings->timer[index -1].mode && (timer >= 12*60)) { - timer = -(timer - (12*60)); - } - rule_param = String(timer); + rule_param = String(TimerGetTimeOfDay(index -1)); } } } @@ -800,11 +796,7 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved) #if defined(USE_TIMERS) for (uint32_t i = 0; i < MAX_TIMERS; i++) { snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1); - int32_t timer = Settings->timer[i].time; - if (Settings->timer[i].mode && (timer >= 12*60)) { - timer = -(timer - 12*60); - } - RulesVarReplace(commands, stemp, String(timer)); + RulesVarReplace(commands, stemp, String(TimerGetTimeOfDay(i))); } #if defined(USE_SUNRISE) RulesVarReplace(commands, F("%SUNRISE%"), String(SunMinutes(0)));