arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.97k stars 4.77k forks source link

in Rules, BREAK doesn't work as descirbed #20672

Closed mrneutron42 closed 7 months ago

mrneutron42 commented 7 months ago

PROBLEM DESCRIPTION

A clear and concise description of what the problem is. In trying to write a rule that has the BREAK command, I discovered that BREAK does not function as described in the documentation. Putting BREAK at the end of a rule section does not stop the execution of the remaining rules that follow, within the rule set. Rule3 in my ruleset listed below shows the failing behavior.

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [x] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
21:32:42.658 CMD: Backlog Rule1; Rule2; Rule3
21:32:42.784 RSL: RESULT = {"Rule1":{"State":"OFF","Once":"OFF","StopOnError":"OFF","Length":116,"Free":395,"Rules":"ON Time#Minute|5 DO Ping4 8.8.8.8 ENDON   ON Ping#8.8.8.8#Success==0 DO Backlog Power1 0; Delay 150; Power1 1; ENDON"}}
21:32:43.292 RSL: RESULT = {"Rule2":{"State":"OFF","Once":"OFF","StopOnError":"OFF","Length":125,"Free":386,"Rules":"ON Time#Minute|3 DO Ping4 192.168.7.223 ENDON ON Ping#192.168.7.223#Success>1 DO Backlog Power1 0; Delay 100; Power1 1; ENDON"}}
21:32:43.864 RSL: RESULT = {"Rule3":{"State":"ON","Once":"OFF","StopOnError":"OFF","Length":266,"Free":245,"Rules":"ON Time#Minute|2 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224 ENDON  ON Ping#192.168.7.223#Success<1 DO DELAY 10 BREAK  ON Ping#192.168.7.224#Success<1 DO DELAY 10 BREAK  ON Ping#192.168.7.223#Success>1 DO Backlog DELAY 10; Power1 0; Delay 100; Power1 1 ENDON"}}

Rule1 works as expected.
Rule2 works as expected.
Rule3 does not work, due to the BREAK command not functioning.
- [x] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:
21:50:00.543 RUL: TIME#MINUTE|2 performs "Backlog Ping4 192.168.7.223; Ping4 192.168.7.224"
21:50:00.546 SRC: Rule
21:50:00.549 CMD: Grp 0, Cmd 'BACKLOG', Idx 1, Len 40, Pld -99, Data 'Ping4 192.168.7.223; Ping4 192.168.7.224'
21:50:00.758 SRC: Backlog
21:50:00.761 CMD: Grp 0, Cmd 'PING', Idx 4, Len 13, Pld 192, Data '192.168.7.223'
21:50:00.765 WIF: DNS resolved '192.168.7.223' (192.168.7.223) in 0 ms
21:50:00.770 RSL: RESULT = {"Ping":"Done"}
21:50:00.873 WIF: Checking connection...
21:50:00.893 CMD: 
21:50:00.895 SRC: Serial
21:50:00.964 SRC: Backlog
21:50:00.967 CMD: Grp 0, Cmd 'PING', Idx 4, Len 13, Pld 192, Data '192.168.7.224'
21:50:00.972 WIF: DNS resolved '192.168.7.224' (192.168.7.224) in 0 ms
21:50:00.977 RSL: RESULT = {"Ping":"Done"}
21:50:00.993 CMD: 
21:50:00.995 SRC: Serial
21:50:01.164 CMD: 
21:50:01.167 SRC: Serial
21:50:01.239 CMD: 
21:50:01.241 SRC: Serial
21:50:01.314 CMD: 
21:50:01.316 SRC: Serial
21:50:01.388 CMD: 
21:50:01.390 SRC: Serial
21:50:01.462 CMD: 
21:50:01.464 SRC: Serial
21:50:01.534 CMD: 
21:50:01.536 SRC: Serial
21:50:01.611 CMD: 
21:50:01.613 SRC: Serial
21:50:01.682 CMD: 
21:50:01.684 SRC: Serial
21:50:01.754 CMD: 
21:50:01.756 SRC: Serial
21:50:01.828 CMD: 
21:50:01.831 SRC: Serial
21:50:01.900 CMD: 
21:50:01.902 SRC: Serial
21:50:01.972 CMD: 
21:50:01.974 SRC: Serial
21:50:02.050 CMD: 
21:50:02.052 SRC: Serial
21:50:05.075 RSL: RESULT = {"Ping":{"192.168.7.224":{"Reachable":false,"IP":"192.168.7.224","Success":0,"Timeout":4,"MinTime":0,"MaxTime":0,"AvgTime":0}}}
21:50:05.159 RUL: PING#192.168.7.224#SUCCESS<1 performs "DELAY 10"
21:50:05.298 SRC: Rule
21:50:05.301 CMD: Grp 0, Cmd 'DELAY', Idx 1, Len 2, Pld 10, Data '10'
21:50:05.304 RSL: RESULT = {"Delay":10}
21:50:05.397 RSL: RESULT = {"Ping":{"192.168.7.223":{"Reachable":true,"IP":"192.168.7.223","Success":3,"Timeout":1,"MinTime":12,"MaxTime":43,"AvgTime":26}}}
21:50:05.776 RUL: PING#192.168.7.223#SUCCESS>1 performs "Backlog DELAY 10; Power1 0; Delay 100; Power1 1"
21:50:05.000 SRC: Rule
21:50:05.002 CMD: Grp 0, Cmd 'BACKLOG', Idx 1, Len 39, Pld -99, Data 'DELAY 10; Power1 0; Delay 100; Power1 1'
21:50:06.281 SRC: Backlog
21:50:06.284 CMD: Grp 0, Cmd 'DELAY', Idx 1, Len 2, Pld 10, Data '10'
21:50:06.288 RSL: RESULT = {"Delay":10}
21:50:07.298 SRC: Backlog
21:50:07.301 CMD: Grp 0, Cmd 'POWER', Idx 1, Len 1, Pld 0, Data '0'
21:50:07.305 RSL: RESULT = {"POWER":"OFF"}
21:50:07.308 RSL: POWER = OFF
21:50:07.505 SRC: Backlog
21:50:07.508 CMD: Grp 0, Cmd 'DELAY', Idx 1, Len 3, Pld 100, Data '100'
21:50:07.512 RSL: RESULT = {"Delay":100}
21:50:15.649 CMD: b
21:50:15.651 SRC: Serial
21:50:15.654 CMD: Grp 0, Cmd 'B', Idx 1, Len 0, Pld -99, Data ''
21:50:15.659 RSL: RESULT = {"Command":"Unknown"}
21:50:15.859 SRC: Backlog
21:50:15.862 CMD: Grp 0, Cmd 'POWER', Idx 1, Len 1, Pld 1, Data '1'
21:50:15.866 RSL: RESULT = {"POWER":"ON"}
21:50:15.869 RSL: POWER = ON
21:50:21.824 WIF: Checking connection...
21:50:23.545 WIF: Sending Gratuitous ARP

TO REPRODUCE

Steps to reproduce the behavior: Enter rule including BREAK command, and enable rule. You will observe that the last section of the rule runs EVERY TIME, instead of being skipped over when the ping to 192.168.7.223 or 192.168.7.224 fails.

Rule3 ON Time#Minute|2 DO Backlog Ping4 192.168.7.223; Ping4 192.168.7.224 ENDON ON Ping#192.168.7.223#Success<1 DO DELAY 10 BREAK ON Ping#192.168.7.224#Success<1 DO DELAY 10 BREAK ON Ping#192.168.7.223#Success>1 DO Backlog DELAY 10; Power1 0; Delay 100; Power1 1 ENDON Rule3 1

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen. If the ping command to 192.168.7.223 fails to get a response, I expect the BREAK command to skip the rest of the rule. If the ping command to 192.168.7.224 fails to get a response, I expect the BREAK command to skip the rest of the rule. In my weblog 4 console output, the ping to 192.168.7.224 failed, and the BREAK command should have skipped the last part of the rule that power cycled the switch, but it was executed anyway and a power cycle ocurred.

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

This issue existed in 2020 and it still does. https://github.com/arendst/Tasmota/issues/7985

(Please, remember to close the issue when the problem has been addressed)

sfromis commented 7 months ago

What you seem to be misunderstanding is that rules is not some sort of sequential execution where you can mix different triggers to manage filtering and timing. It is instead events where each new event (like separate Ping command results) is starting independent (but possibly partially interleaved) passes through the rules engine, and break only works within each of those passes.

The references to break facilitating some sort of if/else logic is only within the processing of the same event, like results from a single Ping command, not when you are firing off more than one. Using break within your 224 rule is not affecting the 223 rules, and vice versa.

Also, using Delay in rules is a broken strategy, as these intervals can be cut short by other commands executing. Use RuleTimer when you want to control "later execution".