From 2e25ab141253c890f92bf766b93b558aae4b563d Mon Sep 17 00:00:00 2001 From: lukaszdrukasz <48068326+lukaszdrukasz@users.noreply.github.com> Date: Wed, 11 Sep 2019 11:01:39 +0200 Subject: [PATCH] Updated Rule Cookbook (markdown) --- Rule-Cookbook.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Rule-Cookbook.md b/Rule-Cookbook.md index 81817589..4956c142 100644 --- a/Rule-Cookbook.md +++ b/Rule-Cookbook.md @@ -22,6 +22,7 @@ - [PIR Configuration](Wemos-D1-Mini-and-HC-SR501-PIR-Motion-Sensor#alternative-tasmota-configuration-with-rules-recommended-method) - [Using clock timer to control a luminance-triggered switch only in mornings](#using-clock-timer-to-control-a-luminance-triggered-switch-only-in-mornings) - [Using an external button with single press - double press and hold](#using-an-external-button-with-single-press---double-press-and-hold) +- [ANY action on single/double press for switches AND buttons (rules-based)](#any-action-on-singledouble-press-for-switches-and-buttons-rules-based) - [Enable or disable doorbell relay with HTTP call](#enable-or-disable-doorbell-relay-with-http-call) - [Force automatic reconnection to MQTT server via SD DNS](#force-automatic-reconnection-to-mqtt-server-via-sd-dns) - [Change distance to percentage](#change-distance-to-percentage) @@ -879,7 +880,36 @@ Rule 1 ``` [Back To Top](#top) +------------------------------------------------------------------------------ +#### ANY action on single/double press for switches AND buttons (rules-based) + +There is a way to program this using rules if you wish to sacrifice a variable.
+ +**Commands:** +``` +SwitchMode 5 +Rule1 +on switch1#state==2 do add1 1 endon +on switch1#state==2 do power1 2 endon +on var1#state!=0 do backlog delay 6;var1 0 endon +on var1#state==2 do publish cmnd/othertasmota/POWER toggle endon + +Rule1 on +``` + +**Explanation:** + +- each toggle of the switch triggers first condition and adds 1 to our variable (var1 in the example), +- each toggle of the switch toggles the associated relay (```power1 2``` - but can do anything else instead, ```publish``` for example) +- when var1 changes to non zero, we set it back to 0 but after a ```delay``` (arbitrarily chosen 6 here - 0.6 seconds) +- when var1 reaches 2 (i.e. the switch has been toggled twice within the last 0.6 seconds), desired action is triggered (here: ```publish``` to othertasmota) + +**Result:** + +Every time you press the switch your light toggles state (as it should) but if you do it twice in a rapid succession, you can trigger another action elsewhere. + +[Back To Top](#top) ------------------------------------------------------------------------------ #### Enable or disable doorbell relay with HTTP call