mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Merge pull request #10352 from barbudor/dev_ruletimer0
RuleTimer0 applies to all RuleTimers
This commit is contained in:
commit
2f120d86a0
@ -974,9 +974,8 @@ void RulesEvery100ms(void)
|
||||
|
||||
void RulesEverySecond(void)
|
||||
{
|
||||
if (Settings.rule_enabled && !Rules.busy) { // Any rule enabled
|
||||
char json_event[120];
|
||||
|
||||
if (Settings.rule_enabled && !Rules.busy) { // Any rule enabled
|
||||
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
|
||||
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);
|
||||
}
|
||||
@ -2123,22 +2124,30 @@ 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;
|
||||
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++) {
|
||||
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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user