Add rule variables %timer1% to %timer16%

Add rule variables %timer1% to %timer16% (#14619)
This commit is contained in:
Theo Arends 2022-02-04 16:18:56 +01:00
parent c113a2a4b8
commit 0d7ea9eb28
3 changed files with 26 additions and 22 deletions

View File

@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## [2022.1.4] ## [2022.1.4]
### Added ### Added
- Rule variables %timer1% to %timer16% (#14619)
### Changed ### Changed
- Version display from 2022.01.3 to 2022.1.4 - Version display from 2022.01.3 to 2022.1.4

View File

@ -129,6 +129,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
- Tasmota favicon to webbrowser tab [#14322](https://github.com/arendst/Tasmota/issues/14322) - Tasmota favicon to webbrowser tab [#14322](https://github.com/arendst/Tasmota/issues/14322)
- Support for BME688 with latest Bosch-Sensor-API library [#14513](https://github.com/arendst/Tasmota/issues/14513) - Support for BME688 with latest Bosch-Sensor-API library [#14513](https://github.com/arendst/Tasmota/issues/14513)
- Rule variable %color% [#14572](https://github.com/arendst/Tasmota/issues/14572) - Rule variable %color% [#14572](https://github.com/arendst/Tasmota/issues/14572)
- Rule variables %timer1% to %timer16% [#14619](https://github.com/arendst/Tasmota/issues/14619)
- Support for MQ analog sensor for air quality by Francesco Adriani [#14581](https://github.com/arendst/Tasmota/issues/14581) - Support for MQ analog sensor for air quality by Francesco Adriani [#14581](https://github.com/arendst/Tasmota/issues/14581)
- ESP32 single binary firmware [#14239](https://github.com/arendst/Tasmota/issues/14239) - ESP32 single binary firmware [#14239](https://github.com/arendst/Tasmota/issues/14239)
- ESP32 disable serial console when 3 (ESP32) or 2 (Other models) serial interfaces are requested [#14487](https://github.com/arendst/Tasmota/issues/14487) - ESP32 disable serial console when 3 (ESP32) or 2 (Other models) serial interfaces are requested [#14487](https://github.com/arendst/Tasmota/issues/14487)

View File

@ -464,22 +464,24 @@ bool RulesRuleMatch(uint8_t rule_set, String &event, String &rule, bool stop_all
if (rule_param.startsWith(F("%TIMESTAMP%"))) { if (rule_param.startsWith(F("%TIMESTAMP%"))) {
rule_param = GetDateAndTime(DT_LOCAL).c_str(); rule_param = GetDateAndTime(DT_LOCAL).c_str();
} }
#if defined(USE_TIMERS) && defined(USE_SUNRISE) #if defined(USE_TIMERS)
if (rule_param.startsWith(F("%TIMER"))) {
uint32_t index = rule_param.substring(6).toInt();
if ((index > 0) && (index <= MAX_TIMERS)) {
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), index);
if (rule_param.startsWith(stemp)) {
rule_param = String(Settings->timer[index -1].time);
}
}
}
#if defined(USE_SUNRISE)
if (rule_param.startsWith(F("%SUNRISE%"))) { if (rule_param.startsWith(F("%SUNRISE%"))) {
rule_param = String(SunMinutes(0)); rule_param = String(SunMinutes(0));
} }
if (rule_param.startsWith(F("%SUNSET%"))) { if (rule_param.startsWith(F("%SUNSET%"))) {
rule_param = String(SunMinutes(1)); rule_param = String(SunMinutes(1));
} }
#endif // USE_TIMERS and USE_SUNRISE #endif // 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 #endif // USE_TIMERS
#if defined(USE_LIGHT) #if defined(USE_LIGHT)
char scolor[LIGHT_COLOR_SIZE]; char scolor[LIGHT_COLOR_SIZE];
@ -784,15 +786,15 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
snprintf_P(stemp, sizeof(stemp), PSTR("%06X"), ESP_getChipId()); snprintf_P(stemp, sizeof(stemp), PSTR("%06X"), ESP_getChipId());
RulesVarReplace(commands, F("%DEVICEID%"), stemp); RulesVarReplace(commands, F("%DEVICEID%"), stemp);
RulesVarReplace(commands, F("%MACADDR%"), NetworkUniqueId()); RulesVarReplace(commands, F("%MACADDR%"), NetworkUniqueId());
#if defined(USE_TIMERS) && defined(USE_SUNRISE)
RulesVarReplace(commands, F("%SUNRISE%"), String(SunMinutes(0)));
RulesVarReplace(commands, F("%SUNSET%"), String(SunMinutes(1)));
#endif // USE_TIMERS and USE_SUNRISE
#if defined(USE_TIMERS) #if defined(USE_TIMERS)
for (uint32_t i = 0; i < MAX_TIMERS; i++) { for (uint32_t i = 0; i < MAX_TIMERS; i++) {
snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1); snprintf_P(stemp, sizeof(stemp), PSTR("%%TIMER%d%%"), i +1);
RulesVarReplace(commands, stemp, String(Settings->timer[i].time)); RulesVarReplace(commands, stemp, String(Settings->timer[i].time));
} }
#if defined(USE_SUNRISE)
RulesVarReplace(commands, F("%SUNRISE%"), String(SunMinutes(0)));
RulesVarReplace(commands, F("%SUNSET%"), String(SunMinutes(1)));
#endif // USE_SUNRISE
#endif // USE_TIMERS #endif // USE_TIMERS
#if defined(USE_LIGHT) #if defined(USE_LIGHT)
char scolor[LIGHT_COLOR_SIZE]; char scolor[LIGHT_COLOR_SIZE];
@ -1420,18 +1422,18 @@ bool findNextVariableValue(char * &pVarname, float &value)
value = UtcTime(); value = UtcTime();
} else if (sVarName.equals(F("LOCALTIME"))) { } else if (sVarName.equals(F("LOCALTIME"))) {
value = LocalTime(); value = LocalTime();
#if defined(USE_TIMERS) && defined(USE_SUNRISE) #if defined(USE_TIMERS)
} else if (sVarName.startsWith(F("TIMER"))) {
uint32_t index = sVarName.substring(5).toInt();
if (index > 0 && index <= MAX_TIMERS) {
value = Settings->timer[index -1].time;
}
#if defined(USE_SUNRISE)
} else if (sVarName.equals(F("SUNRISE"))) { } else if (sVarName.equals(F("SUNRISE"))) {
value = SunMinutes(0); value = SunMinutes(0);
} else if (sVarName.equals(F("SUNSET"))) { } else if (sVarName.equals(F("SUNSET"))) {
value = SunMinutes(1); value = SunMinutes(1);
#endif #endif // USE_SUNRISE
#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 #endif // USE_TIMERS
// #ifdef USE_ZIGBEE // #ifdef USE_ZIGBEE
// // } else if (sVarName.equals(F("ZBDEVICE"))) { // // } else if (sVarName.equals(F("ZBDEVICE"))) {