mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-26 04:06:34 +00:00
Merge pull request #15230 from barbudor/timer_var_mode_2_3
Fix %TIMERx% variables for negative values
This commit is contained in:
commit
d427220ee4
@ -235,6 +235,22 @@ uint16_t SunMinutes(uint32_t dawn)
|
|||||||
|
|
||||||
#endif // USE_SUNRISE
|
#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)
|
void TimerSetRandomWindow(uint32_t index)
|
||||||
|
@ -477,7 +477,7 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
|
|||||||
if ((index > 0) && (index <= MAX_TIMERS)) {
|
if ((index > 0) && (index <= MAX_TIMERS)) {
|
||||||
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), index);
|
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), index);
|
||||||
if (rule_param.startsWith(stemp)) {
|
if (rule_param.startsWith(stemp)) {
|
||||||
rule_param = String(Settings->timer[index -1].time);
|
rule_param = String(TimerGetTimeOfDay(index -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -796,7 +796,7 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
|
|||||||
#if defined(USE_TIMERS)
|
#if defined(USE_TIMERS)
|
||||||
for (uint32_t i = 0; i < MAX_TIMERS; i++) {
|
for (uint32_t i = 0; i < MAX_TIMERS; i++) {
|
||||||
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1);
|
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1);
|
||||||
RulesVarReplace(commands, stemp, String(Settings->timer[i].time));
|
RulesVarReplace(commands, stemp, String(TimerGetTimeOfDay(i)));
|
||||||
}
|
}
|
||||||
#if defined(USE_SUNRISE)
|
#if defined(USE_SUNRISE)
|
||||||
RulesVarReplace(commands, F("%SUNRISE%"), String(SunMinutes(0)));
|
RulesVarReplace(commands, F("%SUNRISE%"), String(SunMinutes(0)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user