From f70e4ab783aff2a9e652dc5bbb42513cd7221fbc Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Mon, 27 Aug 2018 04:59:17 -0300 Subject: [PATCH] Added time parameters as variable comparison Added %sunrise%, %sunset%, %uptime% and %time% to be used in rules comparison like: on Time#Initialized do backlog event checksunrise=%time%; event checksunset=%time% endon on event#checksunset>%sunset% do power3 1 endon on event#checksunrise<%sunrise% do power3 1 endon --- sonoff/xdrv_10_rules.ino | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 4139d0273..a9941897c 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -155,6 +155,24 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule) break; } } + snprintf_P(stemp, sizeof(stemp), PSTR("%%TIME%%")); + if (rule_param.startsWith(stemp)) { + rule_param = String(GetMinutesPastMidnight()); + } + snprintf_P(stemp, sizeof(stemp), PSTR("%%UPTIME%%")); + if (rule_param.startsWith(stemp)) { + rule_param = String(GetMinutesUptime()); + } +#if defined(USE_TIMERS) && defined(USE_SUNRISE) + snprintf_P(stemp, sizeof(stemp), PSTR("%%SUNRISE%%")); + if (rule_param.startsWith(stemp)) { + rule_param = String(GetSunMinutes(0)); + } + snprintf_P(stemp, sizeof(stemp), PSTR("%%SUNSET%%")); + if (rule_param.startsWith(stemp)) { + rule_param = String(GetSunMinutes(1)); + } +#endif // USE_TIMERS and USE_SUNRISE rule_param.toUpperCase(); snprintf(rule_svalue, sizeof(rule_svalue), rule_param.c_str());