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)
|
void RulesEverySecond(void)
|
||||||
{
|
{
|
||||||
|
char json_event[120];
|
||||||
if (Settings.rule_enabled && !Rules.busy) { // Any rule enabled
|
if (Settings.rule_enabled && !Rules.busy) { // Any rule enabled
|
||||||
char json_event[120];
|
|
||||||
|
|
||||||
if (RtcTime.valid) {
|
if (RtcTime.valid) {
|
||||||
if ((TasmotaGlobal.uptime > 60) && (RtcTime.minute != Rules.last_minute)) { // Execute from one minute after restart every minute only once
|
if ((TasmotaGlobal.uptime > 60) && (RtcTime.minute != Rules.last_minute)) { // Execute from one minute after restart every minute only once
|
||||||
Rules.last_minute = RtcTime.minute;
|
Rules.last_minute = RtcTime.minute;
|
||||||
@ -984,10 +983,12 @@ void RulesEverySecond(void)
|
|||||||
RulesProcessEvent(json_event);
|
RulesProcessEvent(json_event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (uint32_t i = 0; i < MAX_RULE_TIMERS; i++) {
|
}
|
||||||
if (Rules.timer[i] != 0L) { // Timer active?
|
for (uint32_t i = 0; i < MAX_RULE_TIMERS; i++) {
|
||||||
if (TimeReached(Rules.timer[i])) { // Timer finished?
|
if (Rules.timer[i] != 0L) { // Timer active?
|
||||||
Rules.timer[i] = 0L; // Turn off this timer
|
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);
|
snprintf_P(json_event, sizeof(json_event), PSTR("{\"Rules\":{\"Timer\":%d}}"), i +1);
|
||||||
RulesProcessEvent(json_event);
|
RulesProcessEvent(json_event);
|
||||||
}
|
}
|
||||||
@ -2123,21 +2124,29 @@ void CmndRule(void)
|
|||||||
|
|
||||||
void CmndRuleTimer(void)
|
void CmndRuleTimer(void)
|
||||||
{
|
{
|
||||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RULE_TIMERS)) {
|
if (XdrvMailbox.index > MAX_RULE_TIMERS)
|
||||||
if (XdrvMailbox.data_len > 0) {
|
return;
|
||||||
#ifdef USE_EXPRESSION
|
int i = XdrvMailbox.index, max_i = XdrvMailbox.index;
|
||||||
float timer_set = evaluateExpression(XdrvMailbox.data, XdrvMailbox.data_len);
|
if (0 == i) {
|
||||||
Rules.timer[XdrvMailbox.index -1] = (timer_set > 0) ? millis() + (1000 * timer_set) : 0;
|
i = 1;
|
||||||
#else
|
max_i = MAX_RULE_TIMERS;
|
||||||
Rules.timer[XdrvMailbox.index -1] = (XdrvMailbox.payload > 0) ? millis() + (1000 * XdrvMailbox.payload) : 0;
|
|
||||||
#endif // USE_EXPRESSION
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
#ifdef USE_EXPRESSION
|
||||||
|
float timer_set = evaluateExpression(XdrvMailbox.data, XdrvMailbox.data_len);
|
||||||
|
timer_set = (timer_set > 0) ? millis() + (1000 * timer_set) : 0;
|
||||||
|
#else
|
||||||
|
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 (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)
|
void CmndEvent(void)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user