From 0eebdf86208e04297c70c1f3a15e1ee040bf8c79 Mon Sep 17 00:00:00 2001 From: cybermaus Date: Tue, 25 Oct 2022 22:34:08 +0200 Subject: [PATCH 1/2] Deduplicate code from xdrv_10_rules.ino Turns out this code was already done in xdrv_09_timers.ino --- tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino index 6686b8770..49342df27 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_10_rules.ino @@ -1458,19 +1458,7 @@ bool findNextVariableValue(char * &pVarname, float &value) } else if (sVarName.startsWith(F("TIMER"))) { uint32_t index = sVarName.substring(5).toInt(); if (index > 0 && index <= MAX_TIMERS) { - value = Settings->timer[index -1].time; -#if defined(USE_SUNRISE) - // Correct %timerN% values for sunrise/sunset timers - if ((1 == Settings->timer[index -1].mode) || (2 == Settings->timer[index -1].mode)) { - // in this context, time variable itself is merely an offset, with <720 being negative - value += -720 + SunMinutes(Settings->timer[index -1].mode -1); - if (2 == Settings->timer[index -1].mode) { - // To aid rule comparative statements, sunset past midnight (high lattitudes) is expressed past 24h00 - // So sunset at 00h45 is at 24h45 - if (value < 360) { value += 1440; } - } - } -#endif // USE_SUNRISE + value = TimerGetTimeOfDay(index -1); } #if defined(USE_SUNRISE) } else if (sVarName.equals(F("SUNRISE"))) { From a47f6baf2fc36ba903392a27263587c2d125caa4 Mon Sep 17 00:00:00 2001 From: cybermaus Date: Tue, 25 Oct 2022 22:39:30 +0200 Subject: [PATCH 2/2] Deduplicate xdrv_09_timers.ino also Turns out even TimerGetTimeOfDay was duplicate code from ApplyTimerOffsets Did add a fix for the permanent day/night situation --- tasmota/tasmota_xdrv_driver/xdrv_09_timers.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_09_timers.ino b/tasmota/tasmota_xdrv_driver/xdrv_09_timers.ino index 438ade4d5..8c1fd530e 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_09_timers.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_09_timers.ino @@ -253,10 +253,10 @@ uint16_t TimerGetTimeOfDay(uint8_t 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; + ApplyTimerOffsets(&xtimer); + xtime = xtimer.time; + if (xtime==2047 && xtimer.mode==1) xtime *= -1; // Sun always has already rises + if (xtime==2046 && xtimer.mode==2) xtime *= -1; // Sun always has already set } #endif return xtime;