Remove rules enumeration

Michael Ingraham 2019-07-19 10:35:35 -04:00
parent ce225193c7
commit a8a5f9f251
1 changed files with 75 additions and 75 deletions

@ -1,41 +1,41 @@
<a id="top"></a>
1. [Use long press action on a switch](#1-use-long-press-action-on-a-switch)
2. [Execute any MQTT message when a button is pressed](#2-execute-any-mqtt-message-when-a-button-is-pressed)
3. [Execute Several Commands when a Timer Expires](#3-execute-several-commands-when-a-timer-expires)
4. [Usage of one-shot (once)](#4-usage-of-one-shot-once)
5. [Use of Variables and tele-](#5-use-of-variables-and-tele-)
6. [Use a Potentiometer](#6-use-a-potentiometer)
7. [Setting Variables](#7-setting-variables)
8. [Control device LEDs with Relays](#8-control-device-leds-with-relays)
9. [Simple Thermostat Example](#9-simple-thermostat-example)
10. [Simple Staircase Timer](#10-simple-staircase-timer)
- [Advanced PIR rules for Staircase](#10a-advanced-pir-rules-for-staircase)
11. [Energy Saving Smart Switch](#11-energy-saving-smart-switch)
12. [Controlling Timers Enable from a switch](#12-controlling-timers-enable-from-a-switch)
13. [Toggle a Relay only when holding the button for 2 seconds](#13-toggle-a-relay-only-when-holding-the-button-for-2-seconds)
14. [Make sure light is on at night](#14-rule-to-make-sure-light-is-on-at-night)
15. [Enable a PIR Switch only at night](#15-rule-to-enable-a-pir-switch-only-at-night)
- [Simple PIR Config](Wemos-D1-Mini-and-HC-SR501-PIR-Motion-Sensor#alternative-tasmota-configuration-with-rules-recommended-method)
16. [Using an external button with single press - double press and hold](#16-using-an-external-button-with-single-press---double-press-and-hold)
17. [Enable or disable doorbell relay with HTTP call](#17-rule-to-enable-or-disable-doorbell-relay-with-http-call)
18. [Force automatic reconnection to MQTT server via SD DNS](#18-rule-to-force-automatic-reconnection-to-mqtt-server-via-sd-dns)
19. [Change distance to percentage](#19-rule-to-change-distance-to-percentage)
20. [Rules to distinguish Switch1 and Switch2 without the use of Relay1 and Relay2](Rules/#20-rules-to-distinguish-switch1-and-switch2-without-the-use-of-relay1-and-relay2)
21. [Rule for receiving state of intercom doorbell (or anything that triggers your SWITCHX more than one times).](#21-rule-for-receiving-state-of-intercom-doorbell-or-anything-that-triggers-your-switchx-more-than-one-times)
22. [Invoking rules using clock timer to control a luminance-triggered switch only in mornings](#22-invoking-rules-using-clock-timer-to-control-a-luminance-triggered-switch-only-in-mornings)
23. [Prevent Wemos D1 mini load overcurrent](#23-prevent-wemos-d1-mini-load-overcurrent)
24. [Using dummy relays to send Serial codes to the MCU](#24-Using-dummy-relays-to-send-Serial-codes-to-the-MCU)
25. [Arithmetic Commands to be used with VARs](#25-arithmetic-commands-to-be-used-with-vars)
- [Sending the value of a sensor to MQTT only when a delta is reached](#sending-the-value-of-a-sensor-to-mqtt-only-when-a-delta-is-reached)
- [Adjust the value of a sensor and send it by MQTT](#adjust-the-value-of-a-sensor-and-send-it-by-mqtt)
26. [Switch relays via serial interface](#26-Switch-relays-via-serial-interface)
27. [Using BREAK to simulate IF..ELSEIF..ELSE..ENDIF](#27-Using-BREAK-to-simulate-IFELSEIFELSEENDIF)
28. [Adjust PowerDelta according to current Power values](#28-adjust-powerdelta-according-to-current-power-values)
29. [Simple solar heater control](#29-simple-solar-heater-control)
30. [IR Forward](#30-ir-forward)
- [Use long press action on a switch](#use-long-press-action-on-a-switch)
- [Execute any MQTT message when a button is pressed](#execute-any-mqtt-message-when-a-button-is-pressed)
- [Execute Several Commands when a Timer Expires](#execute-several-commands-when-a-timer-expires)
- [Usage of one-shot (once)](#usage-of-one-shot-once)
- [Use of Variables and tele-](#use-of-variables-and-tele-)
- [Use a Potentiometer](#use-a-potentiometer)
- [Setting Variables](#setting-variables)
- [Control device LEDs with Relays](#control-device-leds-with-relays)
- [Thermostat Example](#thermostat-example)
- [Staircase Timer](#staircase-timer)
- [Advanced PIR rules for Staircase](#advanced-pir-rules-for-staircase)
- [Energy Saving Smart Switch](#energy-saving-smart-switch)
- [Controlling Timers Enable from a switch](#controlling-timers-enable-from-a-switch)
- [Toggle a Relay only when holding the button for 2 seconds](#toggle-a-relay-only-when-holding-the-button-for-2-seconds)
- [Make sure light is on at night](#rule-to-make-sure-light-is-on-at-night)
- [Enable a PIR Switch only at night](#rule-to-enable-a-pir-switch-only-at-night)
- [PIR Config](#Wemos-D1-Mini-and-HC-SR501-PIR-Motion-Sensor#alternative-tasmota-configuration-with-rules-recommended-method)
- [Using an external button with single press - double press and hold](#using-an-external-button-with-single-press---double-press-and-hold)
- [Enable or disable doorbell relay with HTTP call](#rule-to-enable-or-disable-doorbell-relay-with-http-call)
- [Force automatic reconnection to MQTT server via SD DNS](#rule-to-force-automatic-reconnection-to-mqtt-server-via-sd-dns)
- [Change distance to percentage](#rule-to-change-distance-to-percentage)
- [Rules to distinguish Switch1 and Switch2 without the use of Relay1 and Relay2](#rules-to-distinguish-switch1-and-switch2-without-the-use-of-relay1-and-relay2)
- [Rule for receiving state of intercom doorbell (or anything that triggers your SWITCHX more than one times).](#rule-for-receiving-state-of-intercom-doorbell-or-anything-that-triggers-your-switchx-more-than-one-times)
- [Invoking rules using clock timer to control a luminance-triggered switch only in mornings](#invoking-rules-using-clock-timer-to-control-a-luminance-triggered-switch-only-in-mornings)
- [Prevent Wemos D1 mini load overcurrent](#prevent-wemos-d1-mini-load-overcurrent)
- [Using dummy relays to send Serial codes to the MCU](#Using-dummy-relays-to-send-Serial-codes-to-the-MCU)
- [Arithmetic Commands to be used with VARs](#arithmetic-commands-to-be-used-with-vars)
- [Sending the value of a sensor to MQTT only when a delta is reached](#sending-the-value-of-a-sensor-to-mqtt-only-when-a-delta-is-reached)
- [Adjust the value of a sensor and send it by MQTT](#adjust-the-value-of-a-sensor-and-send-it-by-mqtt)
- [Switch relays via serial interface](#Switch-relays-via-serial-interface)
- [Using BREAK to simulate IF..ELSEIF..ELSE..ENDIF](#Using-BREAK-to-simulate-IFELSEIFELSEENDIF)
- [Adjust PowerDelta according to current Power values](#adjust-powerdelta-according-to-current-power-values)
- [Solar heater control](#solar-heater-control)
- [IR Forward](#ir-forward)
------------------------------------------------------------------------------
#### 1. Use long press action on a switch
#### Use long press action on a switch
#### NOTE: This example is for GPIOs defined as switches not buttons
@ -52,7 +52,7 @@ Notice we use `Rule` which edits `Rule1` rule set. They can be used interchangea
------------------------------------------------------------------------------
#### 2. Execute any MQTT message when a button is pressed
#### 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).
A problem with this solution is that on a Sonoff 4CH all four buttons will be sending the same MQTT topic using only a different Power index number like `cmnd/ButtonTopic/power3 toggle`.
@ -80,7 +80,7 @@ Result
------------------------------------------------------------------------------
#### 3. Execute several commands when a Timer expires
#### 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.
Hardware
@ -103,7 +103,7 @@ If you want to have blink functionality define a rule like `on clock#Timer=5 do
------------------------------------------------------------------------------
#### 4. Usage of one-shot (once)
#### 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.
Rule
@ -122,8 +122,8 @@ 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.
#### 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.
Hardware
- Sonoff TH or Wemos D1 mini
@ -146,7 +146,7 @@ Clever Dickies now finally have a way to send Temperatures from multiple DS18B20
------------------------------------------------------------------------------
#### 6. Use a potentiometer
#### 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.
Hardware
@ -176,7 +176,7 @@ NOTE: You might want to execute command `SaveData 2` to reduce flash writes ;-)
------------------------------------------------------------------------------
#### 7. Setting variables
#### Setting variables
Demonstrate the use of variables. Make sure to execute commands `Rule 4`(Disable one-shot detection) first when trying the following example.
* Set a variable
@ -240,7 +240,7 @@ Well at least not as you probably would expect. The var1 value used by the power
[Back To Top](#top)
------------------------------------------------------------------------------
#### 8. Control device LEDs with Relays
#### Control device LEDs with Relays
If a device has more than one relay and LEDs on different GPIOs (not connected to the relay) you need to use rules to display current relay status on LEDs. This example is a 3 gang wall switch. Instead of LEDs you need to assign 3 dummy relays that will be controlled when the real relays are switched to reflect their status.
```
@ -256,7 +256,7 @@ Note: This method doubles the number of flash writes. [Link to the device](https
------------------------------------------------------------------------------
#### 9. Simple Thermostat Example
#### Thermostat Example
As example, to be used on a Sonoff TH10 with Sensor Si7021
@ -266,13 +266,13 @@ The set point values can be changed on the fly by mqtt or console commands
If the Temperature sensor disconnects, the outputs will shutdown until the sensor is back again and will resume operation.
When the device is power up, the thermostat also waits until the sensor value to resume operation.
Inital Config:
Initial Config:
* Available physical button as **switch1**
* **Relay1** will be used the controller
* **Rules** must be used to control Relay so the pushbutton must only control **switch1** and not directly control the relay - For this we use SwitchMode1 3 as described below and create the necessary rules because the pushbutton control of the relay is only disabled when the rules are in place.
Inital config on console:
Initial config on console:
* `SwitchMode1 3` <- Use the switch1 as pushbutton (It will allow us to disable the link between the button and the relay by inserting a rule to dictate what the pushbutton will do - **NOTE: Until rules are created the pushbutton will still control the relay!**)
* `Rule 1 ` <- turn on rules
@ -288,7 +288,7 @@ Inital config on console:
Rules:
On boot start a watch dog timer to check temp sensor connection.
On boot start a watchdog timer to check temp sensor connection.
`Rule on system#boot do RuleTimer1 70 endon`
An available button is configured as switch to set thermostat ON or OFF
@ -364,7 +364,7 @@ TIMERS:
------------------------------------------------------------------------------
#### 10. Simple Staircase Timer
#### Staircase Timer
**Rule:**
`Rule1 on button1#state do backlog power1 %value%; RuleTimer1 600 endon on Rules#Timer=1 do power1 off endon`
@ -387,7 +387,7 @@ TIMERS:
[Back To Top](#top)
------------------------------------------------------------------------------
#### 10.a. Advanced PIR rules for Staircase
#### Advanced PIR rules for Staircase
Example works fine on a Wemos D1 Mini. Used as night light with motion sensor or as ambient light on floor or kitchen.
I connect an LED Strip WS2812 on D1 and the PIR on D2 and a LDR on A0 (voltage divider with 10k ohm resistor)
@ -447,7 +447,7 @@ The LEDs turn off after the RuleTimer expires
------------------------------------------------------------------------------
#### 11. Energy Saving Smart Switch
#### Energy Saving Smart Switch
Example of a switch controlling a light with a condition of a required amount of lux.
@ -471,7 +471,7 @@ Rule on switch1#state=1 do var1 100 endon on switch1#state=0 do backlog var1 0;
------------------------------------------------------------------------------
#### 12. Controlling Timers Enable from a Switch
#### Controlling Timers Enable from a Switch
Assuming that your switch is on `GPIO00` and configured as `Switch1`:
@ -490,7 +490,7 @@ If you don't set Switchmode1 or it is equal 0, it will only have Switch1#state=2
------------------------------------------------------------------------------
#### 13. Toggle a Relay only when holding the button for 2 seconds
#### Toggle a Relay only when holding the button for 2 seconds
The following example is to explain how to catch and use the HOLD feature for buttons.
@ -511,7 +511,7 @@ Rule 1
`ButtonTopic 0` : (default) To not use topics for buttons <br>
`SetOption1 1` : Allow only single, double and hold press button actions <br>
`SetOption32 20` : Set key hold time from 0.1 to 10 seconds (20 = 2 seconds) <br>
`Rule on button1#state=3 do power1 2 endon` : When holding the button1 for 2 seconds it wil toggle relay 1 (state = 3 means HOLD) <br>
`Rule on button1#state=3 do power1 2 endon` : When holding the button1 for 2 seconds it will toggle relay 1 (state = 3 means HOLD) <br>
`on button1#state=2 do delay endon` : Do nothing when short pressing the button1 (state = 2 means TOGGLE) <br>
`Rule 1` : To enable rules
@ -533,9 +533,9 @@ Rule 1
------------------------------------------------------------------------------
#### 14. Rule to Make Sure Light is on at Night
#### Rule to Make Sure Light is on at Night
Using Timers, you can be set to turn on and off a light for iluminate a street/patio by night. But if the Sonoff Device has no power at the trigger time, then, when it powers up, the light will be off all night. So, as a failsafe, can be implemented a conditional control to be checked at Sonoff Startup with rules.
Using Timers, you can be set to turn on and off a light for illuminate a street/patio by night. But if the Sonoff Device has no power at the trigger time, then, when it powers up, the light will be off all night. So, as a failsafe, can be implemented a conditional control to be checked at Sonoff Startup with rules.
Set Timers to turn on your light at Sunset and Turn off at sunrise.
Use `poweronstate 0` in order to start with lights off when powering up your Sonoff.
@ -556,7 +556,7 @@ IF %time%>%sunset DO power1 1 / IF %time%<%sunrise DO power1 1
------------------------------------------------------------------------------
#### 15. Rule to enable a PIR Switch only at night
#### Rule to enable a PIR Switch only at night
PreInfo:
- PIR HC-SR501
@ -580,7 +580,7 @@ Rule1 1
------------------------------------------------------------------------------
#### 16. Using an external button with single press - double press and hold
#### Using an external button with single press - double press and hold
You can have all 3 actions but only if defining your GPIO as button. In this case the double press will toggle the relay.
@ -656,7 +656,7 @@ Rule 1
------------------------------------------------------------------------------
#### 17. Rule to enable or disable doorbell relay with HTTP call
#### Rule to enable or disable doorbell relay with HTTP call
When you want to send MQTT messages ( we use domoticz in this example ) and choose when you want the relay (GPIO12) on or off, by simply sending HTTP commands to trigger an event.<br>
@ -714,7 +714,7 @@ http://<tasmotaIP>/cm?&user=<tasmotaUsername>&password=<tasmotaPassword>&cmnd=ev
------------------------------------------------------------------------------
#### 18. Rule to force automatic reconnection to MQTT server via SD DNS
#### Rule to force automatic reconnection to MQTT server via SD DNS
In order to search for the MQTT server using SD-DNS service (a.k.a. Bonjour or Zero Network Configuration) the suggested configuration is to leave the MQTT Host field blank.
@ -745,7 +745,7 @@ mosquitto_pub -h mqtt_server.local -t "cmnd/sonoff-0657/MqttHost" -m ''
------------------------------------------------------------------------------
#### 19. Rule to change distance to percentage
#### Rule to change distance to percentage
When measuring distance and you have the need to see it in percentage of distance.
In the example 100% is everything below 69cm and 0% is everything above 128cm.
@ -764,7 +764,7 @@ on event#pubdata do publish tele/pannrum-temp/SENSOR %var1% endon
------------------------------------------------------------------------------
#### 20. Rules to distinguish Switch1 and Switch2 (without the use of Relay1 and Relay2)
#### Rules to distinguish Switch1 and Switch2 (without the use of Relay1 and Relay2)
When two (or more) switches are defined as input and you want to distinguish these in the RESULT topic without the use of Relays, then consider the following rules.
@ -810,7 +810,7 @@ Output:
------------------------------------------------------------------------------
#### 21. Rule for receiving state of intercom doorbell (or anything that triggers your SWITCHX more than one times).
#### Rule for receiving state of intercom doorbell (or anything that triggers your SWITCHX more than one times).
With analog intercoms you can take out info about ringing from speaker voltage. You can connect GPIO to it via optoisolator and resistor to take out state.
But even with those speaker voltage is dropping so it switches Sonoff multiple times.
@ -835,7 +835,7 @@ on Rules#Timer=1 do backlog var1 0; event BELL=0 endon
```
description:
- turn off switchtopic as it is necessary to trigget Switch2#state
- turn off switchtopic as it is necessary to trigger Switch2#state
- enable rule 1
- on system boot set var1 to 0
- on switch2 click (person pushing doorbell) - var1 += 1; trigger event START
@ -850,7 +850,7 @@ In this case we have lock for 60 seconds for multiple people calls or to be resi
------------------------------------------------------------------------------
#### 22. Invoking Rules using Clock Timer to control a Luminance triggered switch (only in mornings)
#### Invoking Rules using Clock Timer to control a Luminance triggered switch (only in mornings)
##### Background:
Tasmota powers a sonoff basic attached to a TS-2561 Luminance Sensor. This switch toggles a lamp ON or OFF. The switch should work as below:
@ -900,7 +900,7 @@ Rule2 1
[Back To Top](#top)
------------------------------------------------------------------------------
#### 23. Prevent Wemos D1 mini load overcurrent
#### 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.
Hardware
@ -921,7 +921,7 @@ Result
------------------------------------------------------------------------------
#### 24. Using dummy relays to send Serial codes to the MCU
#### Using dummy relays to send Serial codes to the MCU
By having a device (an [Oil Diffusser](https://blakadder.github.io/templates/oil_diffuser_550ml.html)) that controls all its features through an MCU and reports the states in serial codes to the ESP8266 I had to create some rules to control it using the Web UI or standard Power commands.
@ -939,7 +939,7 @@ Rule3 on system#boot do backlog baudrate 9600; seriallog 2; serialsend5 55aa0003
[Back To Top](#top)
------------------------------------------------------------------------------
#### 25. Arithmetic commands to be used with VARs
#### Arithmetic commands to be used with VARs
* ADD
@ -1005,7 +1005,7 @@ on event#sendtemp do publish stat/sonoff/temp %var1% endon
------------------------------------------------------------------------------
#### 26. Switch relays via serial interface
#### Switch relays via serial interface
This example switches a connected relays over the software serial on and off.<br>
Write the following rules:
@ -1029,7 +1029,7 @@ MQT: stat/sonoff-1585B3/POWER = OFF
------------------------------------------------------------------------------
#### 27. Using BREAK to simulate IF..ELSEIF..ELSE..ENDIF
#### Using BREAK to simulate IF..ELSEIF..ELSE..ENDIF
``BREAK`` is an alternative to ``ENDON``. ``BREAK`` will stop the execution for the triggers that follow. If a trigger that ends with ``BREAK`` fires, then the following triggers of that rule will not be executed. This allows to simulate ``IF..ELSEIF..ELSE..ENDIF``
@ -1107,7 +1107,7 @@ Which will result in the following output:
------------------------------------------------------------------------------
#### 28. Adjust PowerDelta according to current Power values
#### Adjust PowerDelta according to current Power values
Power sensor reporting thresholds are set by a percentage change in the Power value by setting [PowerDelta](Commands#powerdelta). Power changes from 10W to 11W (10%) may not be very interesting. But power changes from 1000W to 1100W (also 10%) could be very important. To avoid getting reports for small changes but ensuring that larger power swings are reported, a rule set can be used to create a gradient threshold based on the absolute power values.
This rule also uses the [one-shot feature of rules](#4-usage-of-one-shot-once) to avoid reporting of every small change within a threshold window. The rule (a ON/DO/ENDON rule in this the set) will trigger only once when a threshold is crossed.
@ -1141,14 +1141,14 @@ ELSE // ENERGY#Power changed (i.e. LE 5)
------------------------------------------------------------------------------
#### 29. Simple solar heater control
#### Solar heater control
In a swimming pool, a filter pump and a solar panel is installed. When the sun is shining, the pump should push water through the solar panel, to heat the pool. When it's night or cloudy, the pump should be off, to avoid cooling the pool water through the solar panel. The pump is controlled by a Sonoff TH10 with 2x DS18B20 sensors connected.
3 simple rules:
3 rules:
* Pump should start when solar panel is more than 2 deg warmer than the pool water
* Pump should stop when solar panel is less than 1 deg varmer than the pool water
* Pump should stop when solar panel is less than 1 deg warmer than the pool water
* Pump should not start if the solar panel is below 25 deg celsius.
`t1`: pool temp
@ -1206,13 +1206,13 @@ event t2=30
And watch the relay turn on and off based on the values.
Please note that this example does not support manual override or handle missing sensor data. Take a look at [Simple Thermostat Example](#9-simple-thermostat-example) for examples.
Please note that this example does not support manual override or handle missing sensor data. Take a look at [Thermostat Example](#thermostat-example) for examples.
[Back To Top](#top)
------------------------------------------------------------------------------
#### 30. IR Forward
#### IR Forward
Using one IR receiver and one sender (or both extender) you can simply forward signals from one to another using the following rule
```