Merge pull request #4749 from ascillato/patch-1

Add variable %timestamp% to be used in rules
This commit is contained in:
Theo Arends 2018-12-27 21:53:33 +01:00 committed by GitHub
commit 17bc48add6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -167,6 +167,10 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule)
if (rule_param.startsWith(stemp)) { if (rule_param.startsWith(stemp)) {
rule_param = String(GetMinutesUptime()); rule_param = String(GetMinutesUptime());
} }
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMESTAMP%%"));
if (rule_param.startsWith(stemp)) {
rule_param = GetDateAndTime(DT_LOCAL).c_str();
}
#if defined(USE_TIMERS) && defined(USE_SUNRISE) #if defined(USE_TIMERS) && defined(USE_SUNRISE)
snprintf_P(stemp, sizeof(stemp), PSTR("%%SUNRISE%%")); snprintf_P(stemp, sizeof(stemp), PSTR("%%SUNRISE%%"));
if (rule_param.startsWith(stemp)) { if (rule_param.startsWith(stemp)) {
@ -313,6 +317,7 @@ bool RuleSetProcess(byte rule_set, String &event_saved)
} }
commands.replace(F("%time%"), String(GetMinutesPastMidnight())); commands.replace(F("%time%"), String(GetMinutesPastMidnight()));
commands.replace(F("%uptime%"), String(GetMinutesUptime())); commands.replace(F("%uptime%"), String(GetMinutesUptime()));
commands.replace(F("%timestamp%"), GetDateAndTime(DT_LOCAL).c_str());
#if defined(USE_TIMERS) && defined(USE_SUNRISE) #if defined(USE_TIMERS) && defined(USE_SUNRISE)
commands.replace(F("%sunrise%"), String(GetSunMinutes(0))); commands.replace(F("%sunrise%"), String(GetSunMinutes(0)));
commands.replace(F("%sunset%"), String(GetSunMinutes(1))); commands.replace(F("%sunset%"), String(GetSunMinutes(1)));