From 8a61c25218df2785943e3986d165fad52bba887b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 13 Aug 2018 13:09:22 +0200 Subject: [PATCH] 6.1.1.6 Add modulo option to rules Add modulo option to rules like rule1 on Time#Minute|5 do backlog power on;delay 200;power off endon (#3466) --- sonoff/_changelog.ino | 5 ++++- sonoff/sonoff_version.h | 2 +- sonoff/xdrv_10_rules.ino | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index b985976c8..ef32aab43 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ -/* 6.1.1.5 +/* 6.1.1.6 + * Add modulo option to rules like rule1 on Time#Minute|5 do backlog power on;delay 200;power off endon (#3466) + * + * 6.1.1.5 * Fix some Pow R2 and S31 checksum errors using optimized re-sync * * 6.1.1.4 diff --git a/sonoff/sonoff_version.h b/sonoff/sonoff_version.h index 534ed4d7c..a0b150f7f 100644 --- a/sonoff/sonoff_version.h +++ b/sonoff/sonoff_version.h @@ -20,6 +20,6 @@ #ifndef _SONOFF_VERSION_H_ #define _SONOFF_VERSION_H_ -#define VERSION 0x06010105 +#define VERSION 0x06010106 #endif // _SONOFF_VERSION_H_ diff --git a/sonoff/xdrv_10_rules.ino b/sonoff/xdrv_10_rules.ino index 6bcfb4538..40560f286 100644 --- a/sonoff/xdrv_10_rules.ino +++ b/sonoff/xdrv_10_rules.ino @@ -182,6 +182,11 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule) pos = rule_name.indexOf("="); if (pos > 0) { compare = '='; + } else { + pos = rule_name.indexOf("|"); // Modulo, cannot use % easily as it is used for variable detection + if (pos > 0) { + compare = '%'; + } } } } @@ -236,7 +241,14 @@ bool RulesRuleMatch(byte rule_set, String &event, String &rule) // Step 3: Compare rule (value) if (str_value) { value = CharToDouble((char*)str_value); + int int_value = int(value); + int int_rule_value = int(rule_value); switch (compare) { + case '%': + if ((int_value > 0) && (int_rule_value > 0)) { + if ((int_value % int_rule_value) == 0) { match = true; } + } + break; case '>': if (value > rule_value) { match = true; } break;