mirror of https://github.com/arendst/Tasmota.git
Index for examples
parent
097bf86549
commit
e1b9aec71b
50
Rules.md
50
Rules.md
|
@ -97,11 +97,34 @@ In addition to %varx% other special commands are the words ``mem1`` until ``mem5
|
|||
|
||||
Currently no ``if`` directive or nested rules are supported.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
### Examples
|
||||
|
||||
The following examples will explain some use cases.
|
||||
|
||||
[1. Prevent Wemos D1 mini load overcurrent](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#1-prevent-wemos-d1-mini-load-overcurrent)
|
||||
|
||||
[2. Execute any MQTT message when a button is pressed](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#2-execute-any-mqtt-message-when-a-button-is-pressed)
|
||||
|
||||
[3. Execute Several Commands when a Timer Expires](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#3-execute-several-commands-when-a-timer-expires)
|
||||
|
||||
[4. Usage of one-shot (once)](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#4-usage-of-one-shot-once)
|
||||
|
||||
[5. Use of Variables and tele-](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#5-use-of-variables-and-tele-)
|
||||
|
||||
[6. Use a Potentiometer](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#6-use-a-potentiometer)
|
||||
|
||||
[7. Setting Variables](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#7-setting-variables)
|
||||
|
||||
[8. Arithmetic Commands to be used with VARs](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#8-arithmetic-commands-to-be-used-with-vars)
|
||||
|
||||
[9. Simple Thermostat Example](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#9-simple-thermostat-example)
|
||||
|
||||
[10. Simple Staircase Timer](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#10-simple-staircase-timer)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 1. Prevent Wemos D1 mini load overcurrent
|
||||
As a WS2812 24 led ring draws approximately 24x3x20 mA = 1.44A and the Wemos D1 mini powered from a PC's USB port can only provide up to 0.5A it would be nice to have some kind of mechanism in place to limit the amount of current to the WS2812 ledring to 0.1A. This is still enough to light all 24 leds up to color 202020.
|
||||
|
||||
|
@ -119,6 +142,8 @@ Rule
|
|||
Result
|
||||
- When a user raises brightness to a level using more than 0.1A the rule kicks in and lowers the current by executing command ``Dimmer 10`` and changes the color to Red with command ``Color 10,0,0``.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 2. Execute any MQTT message when a button is pressed
|
||||
When a button is pressed the user has the possibility to send a MQTT message based on FullTopic and ButtonTopic. This MQTT message is going to be received by the MQTT Broker and if there is any other device(s) subscripted to that Topic, it will receive also that message. So this approach can be used for sending messages/commands to MQTT Broker to Home Automation System, and/or sending messages/commands to MQTT Broker to other device(s).
|
||||
|
||||
|
@ -139,6 +164,8 @@ Rule
|
|||
Result
|
||||
- When button 1 is pressed the rule kicks in and sends a MQTT message substituting variable ``%value%`` with the button state like ``cmnd/ring2/power 2``. When button 2 is pressed a MQTT message like ``cmnd/strip1/power 2`` will be sent.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 3. Execute several commands when a Timer expires
|
||||
The default Timer1..16 functionality allows for controlling one output to either off, on, toggle or blink. When rules are enabled the blink option will be replaced by rule functionality allowing much more flexibility.
|
||||
|
||||
|
@ -157,6 +184,8 @@ Result
|
|||
|
||||
If you want to have blink functionality define a rule like ``on clock#timer=5 do power 3 endon``
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 4. Usage of one-shot (once)
|
||||
The rule command once option provides the possibility to trigger only once on a slow change while the change is still within the bounds of the test.
|
||||
|
||||
|
@ -171,6 +200,8 @@ Now the MQTT message will be sent once, and only once, while the condition is me
|
|||
|
||||
It meets the 'hard thermostat' requests that have been common.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 5. Use of variables and tele-
|
||||
Using variables allows for storing sensor results to be used in composing a single HA message like used with Domoticz. To prevent flooding Domoticz with messages we only want to send a message at TelePeriod time. This is achieved by prefixing the SensorName with the label ``tele-``. This example will use a variable storing the temperature to be used together with humidity in one Domoticz MQTT message.
|
||||
|
||||
|
@ -190,6 +221,8 @@ Result
|
|||
|
||||
Clever Dickies now finally have a way to send Temperatures from multiple DS18B20 to Domoticz
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 6. Use a potentiometer
|
||||
Connecting a potentiometer to the Analog A0 input and a rule can be used to control the dimmer state of any device.
|
||||
|
||||
|
@ -215,6 +248,8 @@ Result
|
|||
|
||||
NOTE: You might want to execute command ``SaveData 2`` to reduce flash writes ;-)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 7. Setting variables
|
||||
Demonstrate the use of variables. Make sure to execute commands ``rule 4``(Disable one-shot detection) first when trying the following example.
|
||||
|
||||
|
@ -275,7 +310,9 @@ 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. Arithmetic commands to be used with VARs
|
||||
|
||||
* ADD
|
||||
|
||||
|
@ -327,6 +364,8 @@ on SI7021#temperature>%var1% do backlog var1 %value%; publish stat/sonoff/temp %
|
|||
on SI7021#temperature<%var2% do backlog var2 %value%; publish stat/sonoff/temp %value%; var1 %value%; add1 2; sub2 2 endon
|
||||
```
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 9. Simple Thermostat Example
|
||||
|
||||
As example, to be used on a Sonoff TH10 with Sensor Si7021
|
||||
|
@ -421,7 +460,9 @@ TESTS:
|
|||
* wait more than a minute without using the event temp and the thermostat will turn off as there is no temperature value (like a sensor error or disconnection)
|
||||
* will resume when using again the event temp
|
||||
|
||||
#### 10. simple staircase timer
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
#### 10. Simple Staircase Timer
|
||||
**Rule:**
|
||||
|
||||
`rule1 on button1#state do backlog power1 %value%; ruletimer1 600 endon on rules#timer=1 do power1 off endon`
|
||||
|
@ -438,4 +479,7 @@ TESTS:
|
|||
|
||||
` on rules#timer=1 do power1 off endon`
|
||||
|
||||
* After the ruletimer1 expires the ligth will be switched off (if you forgot to switch it off)
|
||||
* After the ruletimer1 expires the ligth will be switched off (if you forgot to switch it off)
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue