Skip to content

Commit 6f76a55

Browse files
authored
Merge pull request tasmota#555 from barbudor/pr_example_rules_multipress
Update example for button multi-press
2 parents 8257e02 + ee7e06e commit 6f76a55

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

docs/Rules.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -527,42 +527,61 @@ Pressing `I` on the Ikea switch will toggle `backyard` device and pressing `O` t
527527
528528
### Button single press, double press and hold
529529
530-
_[assuming Button1 and Setoption73 0]_
530+
This example show how to assign different behavior to a button **other than Button1**. Button1
531+
has special multi-press behaviors associated with it (see _Note_ in [Multi-Press Functions](Buttons-and-Switches#multi-press-functions)), examples 1 and 2 cannot be applied to Button1.
531532
532-
* single press: Toggle Power1
533+
#### 1st example:
534+
_[assuming Button2 (or >2) and Setoption73 0]_
535+
536+
* single press: Toggle Power2 _(or >2)_
533537
* double press: send a mqtt message
534538
* hold 2 secs: send a different mqtt message
535539
536540
```haskell
537-
Backlog ButtonTopic 0; SetOption1 1; SetOption11 1; SetOption32 20
538-
```
539-
540-
```haskell
541+
Backlog ButtonTopic 0; SetOption1 1; SetOption11 0; SetOption32 20
541542
Rule1
542-
ON button1#state=3 DO publish cmnd/topicHOLD/power 2 ENDON
543-
ON button1#state=2 DO publish cmnd/topicDOUBLEPRESS/power 2 ENDON
543+
ON button2#state=3 DO publish cmnd/topicHOLD/power2 2 ENDON
544+
ON button2#state=2 DO publish cmnd/topicDOUBLEPRESS/power2 2 ENDON
545+
Rule1 1
544546
```
545547
546-
`Rule1 1`
547-
548-
#### Another example:
549-
_[assuming Button1 and Setoption73 0]_
548+
#### 2nd example with `Setoption11 1`:
549+
_[assuming Button2 (or >2) and Setoption73 0]_
550550
551551
* single press: send MQTT message
552-
* double press: Toggle Power1 (SetOption11 swaps single and double press)
552+
* double press: Toggle Power2 _(or >2)_ (SetOption11 swaps single and double press)
553553
* hold 2 secs: send another mqtt message
554554
555555
```haskell
556-
Backlog ButtonTopic 0; SetOption1 1; SetOption11 0; SetOption32 20
556+
Backlog ButtonTopic 0; SetOption1 1; SetOption11 1; SetOption32 20
557+
Rule1
558+
ON button2#state=3 DO publish cmnd/topicHOLD/power2 2 ENDON
559+
ON button2#state=2 DO publish cmnd/topicSINGLEPRESS/power2 2 ENDON
560+
Rule1 1
557561
```
558562
563+
#### 3rd example for Button1:
564+
For assigning different actions to multi-press on Button1, it is mandatory to detach buttons from
565+
their default function using `SetOption73 1`. With `SetOption73 1` buttons only publish a MQTT
566+
message (`stat/tasmota/BUTTON<x> = {"ACTION":"xxxx"}`). To re-assign a specific action, rules must
567+
be used like below:
568+
569+
* single press: Toggle Power1
570+
* double press: send a mqtt message
571+
* hold 2 secs: send a different mqtt message
572+
559573
```haskell
574+
Backlog ButtonTopic 0; SetOption73 1; SetOption32 20
560575
Rule1
576+
ON button1#state=10 DO power1 2 ENDON
561577
ON button1#state=3 DO publish cmnd/topicHOLD/power 2 ENDON
562-
ON button1#state=2 DO publish cmnd/topicSINGLEPRESS/power 2 ENDON
578+
ON button1#state=11 DO publish cmnd/topicDOUBLEPRESS/power 2 ENDON
579+
Rule1 1
563580
```
564581
565-
`Rule1 1`
582+
!!! note
583+
`SetOption73 1` detaches ALL buttons. If you have more than 1 button, you must create rules
584+
for each buttons where you want an action (other than publishing `stat/tasmota/BUTTON<x> = {"ACTION":"xxxx"}`)
566585
567586
----------------------------------------------------------------------------
568587

0 commit comments

Comments
 (0)