Added HOLD Button Example

Adrian Scillato 2018-08-26 22:31:04 -03:00
parent 60642c21ee
commit 85fe126cb8
1 changed files with 31 additions and 2 deletions

@ -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.
------------------------------------------------------------------------------
------------------------------------------------------------------------------
#### 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
------------------------------------------------------------------------------