From 85fe126cb80ccfd45d6e3d7d7dba252815b5c2ee Mon Sep 17 00:00:00 2001 From: Adrian Scillato <35405447+ascillato@users.noreply.github.com> Date: Sun, 26 Aug 2018 22:31:04 -0300 Subject: [PATCH] Added HOLD Button Example --- Rules.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Rules.md b/Rules.md index 351f67e9..8909c57c 100644 --- a/Rules.md +++ b/Rules.md @@ -134,6 +134,8 @@ The following examples will explain some use cases. [12. Controlling Timers Enable from a switch](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#12-controlling-timers-enable-from-a-switch) +[13. Toggle a Relay only when holding the button for 2 seconds](https://github.com/arendst/Sonoff-Tasmota/wiki/Rules#13-toggle-a-relay-only-when-holding-the-button-for-2-seconds) + ------------------------------------------------------------------------------ #### 1. Prevent Wemos D1 mini load overcurrent @@ -532,7 +534,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 +#### 12. Controlling Timers Enable from a Switch Assuming that your switch is on `GPIO00` and configured as `Switch1`: @@ -546,4 +548,31 @@ Switchmode1 1 will make Switch1#state to be 1 when ON and 0 when OFF If you don't set Switchmode1 or it is equal 0, it will only have Switch1#state=2 (toggle) and the previous rule will not work. ------------------------------------------------------------------------------- \ No newline at end of file +------------------------------------------------------------------------------ + +#### 13. 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. + +Behaviour: Disable Button1 Short Press and Toggle Relay1 only when holding the button1 for 2 Seconds. + +Type in the console: + +``` +buttontopic 0 +setoption1 1 +setoption32 20 +rule on button1#state=3 do power1 2 endon on button1#state=2 do delay endon +rule 1 +``` + +**Commands Explanation** + +`buttontopic 0` : (default) To not use topics for buttons +`setoption1 1` : Allow only single, double and hold press button actions +`setoption32 20` : Set key hold time from 0.1 to 10 seconds (20 = 2 seconds) +`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) +`on button1#state=2 do delay endon` : Do nothing when short pressing the button1 (state = 2 means TOGGLE) +`rule 1` : To enable rules + +------------------------------------------------------------------------------