Skip to content

Commit

Permalink
Merge pull request #10352 from barbudor/dev_ruletimer0
Browse files Browse the repository at this point in the history
RuleTimer0 applies to all RuleTimers
  • Loading branch information
arendst authored Jan 3, 2021
2 parents ad11f70 + 5bb682b commit 2f120d8
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions tasmota/xdrv_10_rules.ino
Original file line number Diff line number Diff line change
Expand Up @@ -974,20 +974,21 @@ 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;
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Time\":{\"Minute\":%d}}"), MinutesPastMidnight());
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);
}
Expand Down Expand Up @@ -2123,21 +2124,29 @@ void CmndRule(void)

void CmndRuleTimer(void)
{
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_TIMERS)) {
if (XdrvMailbox.data_len > 0) {
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);
Rules.timer[XdrvMailbox.index -1] = (timer_set > 0) ? millis() + (1000 * timer_set) : 0;
float timer_set = evaluateExpression(XdrvMailbox.data, XdrvMailbox.data_len);
timer_set = (timer_set > 0) ? millis() + (1000 * timer_set) : 0;
#else
Rules.timer[XdrvMailbox.index -1] = (XdrvMailbox.payload > 0) ? millis() + (1000 * XdrvMailbox.payload) : 0;
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 (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();
}
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)
Expand Down

0 comments on commit 2f120d8

Please sign in to comment.