mirror of https://github.com/arendst/Tasmota.git
Updated Expressions in Rules (markdown)
parent
4660f3ab55
commit
ea8ba39cff
|
@ -1,40 +1,44 @@
|
||||||
Starting Tasmota version 6.4.1.14, an optional feature for using mathematical expressions in Tasmota rules was introduced. This feature is disabled by default but can be enabled by compiling from source and removing the comment before #define USE_EXPRESSION in my_user_config.h or even better in user_config_override.h (and of course, #define USE_RULES is also required).
|
Beginning with Tasmota version 6.4.1.14, an optional feature for using mathematical expressions in rules was introduced. This feature is disabled by default but can be enabled by compiling from source and adding `#define USE_EXPRESSION` to `user_config_override.h`. Of course, `#define USE_RULES` is also required (enabled by default).
|
||||||
|
|
||||||
### Once the feature is enabled, the use of expressions is supported in the following commands:
|
### Supported Commands
|
||||||
|
Once the feature is enabled, the use of expressions is supported in the following commands:
|
||||||
* Var
|
* Var
|
||||||
* Mem
|
* Mem
|
||||||
* Ruletimer
|
* RuleTimer
|
||||||
* If (only if the additional #define SUPPORT_IF_STATEMENT is set)
|
* [If conditional statement](Rules---IF-ELSE-ELSEIF-and-AND-OR-Support) (requires `#define SUPPORT_IF_STATEMENT`)
|
||||||
|
|
||||||
|
### Syntax
|
||||||
|
Expressions can use of the following operators. They are listed by the order of operations priority, from higher to lower.
|
||||||
|
* `( )` (parentheses are used to explicitly control the order of operations)
|
||||||
|
* `^` (power)
|
||||||
|
* `%` (modulo, division by zero returns modulo "0")
|
||||||
|
* `*` and `/` (multiplication and division; division by zero returns "0")
|
||||||
|
* `+` and `-` (addition and subtraction)
|
||||||
|
|
||||||
### Expressions can make use of the following operators, by the order of priority from higher to lower:
|
**Order of Operations Example**
|
||||||
* ^ (power)
|
* `1\+2\*2` results in 5.0 as the multiplication is done first due to its higher priority
|
||||||
* % (modulo, division by zero returns modulo "0")
|
* `(1\+2)\*2` results in 6.0
|
||||||
* \* and / (multiplication and division; division by zero returns "0")
|
|
||||||
* \+ and - (addition and substraction)
|
|
||||||
|
|
||||||
**Subexpressions can be put into parentheses.**
|
In addition to numeric constants, the following symbolic values can be used:
|
||||||
|
|
||||||
### Example for priorities:
|
Symbol|Description
|
||||||
* 1\+2\*2 results in 5.0 as the multiplication is done first due to its higher priority
|
-|-
|
||||||
* (1\+2)\*2 results in 6.0
|
|VAR\<x>|variable (\<x> = `1..MAX_RULE_VARS`, e.g., `VAR2`)
|
||||||
|
|MEM\<x>|persistent variable (\<x> = `1..MAX_RULE_MEMS`, e.g., `MEM3`)
|
||||||
|
|TIME|minutes past midnight
|
||||||
|
|UPTIME|uptime minutes
|
||||||
|
|UTCTIME|UTC time, UNIX timestamp, seconds since 01/01/1970
|
||||||
|
|LOCALTIME|local time, UNIX timestamp
|
||||||
|
|SUNRISE|current sunrise time (minutes past midnight)
|
||||||
|
|SUNSET|current sunset time (minutes past midnight)
|
||||||
|
|
||||||
### In addition to numeric constants, the following additional placeholders can be used:
|
Example: `Mem1=((0.5*Var1)+10)*0.7`
|
||||||
* VARx : variable content (x = 1..MAX_RULE_VARS, expample VAR2)
|
|
||||||
* MEMx : mem-variable content (x = 1..MAX_RULE_MEMS, example MEM3)
|
|
||||||
* TIME : minutes past midnight
|
|
||||||
* UPTIME : minutes uptime
|
|
||||||
* UTCTIME : UTC time, UNIX timestamp, seconds since 01/01/1970
|
|
||||||
* LOCALTIME : local time, UNIX timestamp
|
|
||||||
* SUNRISE : current sunrise time (minutes past midnight)
|
|
||||||
* SUNSET : current sunset time (minutes past midnight)
|
|
||||||
|
|
||||||
### Calling convention:
|
To use expressions in the `Var`, `Mem` and `RuleTimer` commands, an equal sign (`=`) character has to be used after the command. If not, the traditional syntax interpretation is used.
|
||||||
To use expressions in the commands Var, Mem and Ruletimer, the "=" character has to be used after the command. If this is not the case, the old logic is applied which doesn't know about expressions.
|
|
||||||
|
|
||||||
Examples: [resulting variable content in [] ]
|
Statement|Var1 Result
|
||||||
* var1=42 [42]
|
-|-
|
||||||
* var1 1+1 [results in the string value "1+1"]
|
`Var1=42`|42
|
||||||
* var1=1+1 [2]
|
`Var1 1+1`|"1+1" (the literal string)
|
||||||
* var1=sunset-sunrise [duration of daylight in minutes]
|
`Var1=1+1`|2
|
||||||
* mem1=((0.5*var1)+10)*0.7
|
`Var1=sunset-sunrise`|duration of daylight in minutes
|
||||||
|
|
Loading…
Reference in New Issue