From ac02bc8288acd68d6442fc1861dc614e79fdb508 Mon Sep 17 00:00:00 2001 From: alexasf Date: Thu, 27 Jan 2022 13:00:49 +0300 Subject: [PATCH] Update xdrv_10_rules.ino Added %timer1% to %timer16% variables to rules --- tasmota/xdrv_10_rules.ino | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index cad3281b6..3144bfdd9 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -48,6 +48,7 @@ * on switch1#state do power2 %value% endon * on analog#a0div10 do publish cmnd/ring2/dimmer %value% endon * on loadavg<50 do power 2 endon + * on Time#Initialized do Backlog var1 0;event checktime=%time% endon on event#checktime>%timer1% do var1 1 endon on event#checktime>=%timer2% do var1 0 endon * on event#checktime do Power1 %var1% endon * * Notes: * Spaces after , around and before are mandatory @@ -471,11 +472,19 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all rule_param = String(SunMinutes(1)); } #endif // USE_TIMERS and USE_SUNRISE +#if defined(USE_TIMERS) + for (uint32_t i = 0; i < MAX_TIMERS; i++) { + snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1); + if (rule_param.startsWith(stemp)) { + rule_param = String(Settings->timer[i].time); + break; + } + } +#endif // USE_TIMERS #if defined(USE_LIGHT) char scolor[LIGHT_COLOR_SIZE]; if (rule_param.startsWith(F("%COLOR%"))) { rule_param = LightGetColor(scolor); - } #endif // #ifdef USE_ZIGBEE // if (rule_param.startsWith(F("%ZBDEVICE%"))) { @@ -778,6 +787,12 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved) RulesVarReplace(commands, F("%SUNRISE%"), String(SunMinutes(0))); RulesVarReplace(commands, F("%SUNSET%"), String(SunMinutes(1))); #endif // USE_TIMERS and USE_SUNRISE +#if defined(USE_TIMERS) + for (uint32_t i = 0; i < MAX_TIMERS; i++) { + snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1); + RulesVarReplace(commands, stemp, String(Settings->timer[i].time)); + } +#endif // USE_TIMERS #if defined(USE_LIGHT) char scolor[LIGHT_COLOR_SIZE]; RulesVarReplace(commands, F("%COLOR%"), LightGetColor(scolor)); @@ -1410,6 +1425,13 @@ bool findNextVariableValue(char * &pVarname, float &value) } else if (sVarName.equals(F("SUNSET"))) { value = SunMinutes(1); #endif +#if defined(USE_TIMERS) + } else if (sVarName.startsWith(F("TIMER"))) { + int index = sVarName.substring(5).toInt(); + if (index > 0 && index <= MAX_TIMERS) { + value = Settings->timer[index-1].time; + } +#endif // USE_TIMERS // #ifdef USE_ZIGBEE // // } else if (sVarName.equals(F("ZBDEVICE"))) { // // value = Z_GetLastDevice();