Added Arithmetic commands examples

Adrian Scillato 2018-06-25 13:34:46 -03:00
parent c39cf53312
commit 812895eb09
1 changed files with 52 additions and 1 deletions

@ -272,8 +272,59 @@ Note that the following won't work:
Well at least not as you probably would expect. The var1 value used by the power1 command will be the value present before the backlog command is executed. This is so, because the rule will replace %var1% BEFORE the backlog commands are put in the backlog-log.
#### 8. Arithmetic commands to be used with `VARs
#### 8. Simple Thermostat Example
* ADD
`ADD1` to `ADD5`: Add a value to `VARx`
Syntax: `ADDx value`
Usage: `ADD1 15`
Result: `VAR1 = VAR1 + 15`
* SUBSTRACT
`SUB1 `to `SUB5`: Substract a value from `VARx`
Syntax: `SUBx value`
Usage: `SUB1 15`
Result: `VAR1 = VAR1 - 15`
* MULTIPLY
`MULT1 `to `MULT5`: Multiply a value to `VARx`
Syntax: `MULTx value`
Usage: `MULT1 15`
Result: `VAR1 = VAR1 * 15`
* SCALE A VALUE
`SCALE1 `to `SCALE5`: Scale a value from a low and high limit to another low and high limit and store it in `VARx` (directly equivalent to MAP arduino command)
Syntax: `SCALEx value, fromLow, fromHigh, toLow, toHigh`
where,
_value_: the number to scale
_fromLow_: the lower bound of the values current range
_fromHigh_: the upper bound of the values current range
_toLow_: the lower bound of the values target range
_toHigh_: the upper bound of the values target range
_(omitted values are taken as zero)_
Usage: `SCALE1 15, 0, 100, 0, 1000`
Result: `VAR1 = 150`
* Example: Sending the value of a sensor to MQTT only when a delta is reached
When it is needed that a sensor value is only sent when it changes a delta, can be solved applying the following rule example:
```
rule
on AM2102#temperature>%var1% do backlog var1 %value%; publish stat/sonoff/temp %var1%; var2 %var1%; add1 2; sub2 2 endon
on AM2102#temperature<%var2% do backlog var2 %value%; publish stat/sonoff/temp %var2%; var1 %var2%; add1 2; sub2 2 endon
```
#### 9. Simple Thermostat Example
As example, to be used on a Sonoff TH10 with Sensor Si7021