Page 1 of 1

Rules: only one "On System#Boot do" !?

Posted: 02 Oct 2022, 11:12
by joost d
I found that in the "Rules" only one rule can contain "On System#Boot do".
If every rule has an "On System#Boot do" then only the first will be executed.
I can't find anything about it in the manual. Is that right?

Re: Rules: only one "On System#Boot do" !?

Posted: 02 Oct 2022, 11:40
by TD-er
Rules parsing is done by trying to match an event.
As soon as it has been matched, rules parsing will stop.

This also means you need to be careful when creating rules for less specific events and more of a "catch-all" version.

For example:

Code: Select all

on foo#bar=1 do
 ...
endon

on foo#bar do
 ...
endon
As you may see, the order of these is quite important.

A few months ago I have added an option to optimize rules order based on the frequency it may have been hit. This would speed up rules parsing.
However I overlooked this use case and thus have removed this optimization :)

Re: Rules: only one "On System#Boot do" !?

Posted: 02 Oct 2022, 12:53
by Ath
joost d wrote: 02 Oct 2022, 11:12 If every rule has an "On System#Boot do" then only the first will be executed.
You seem to expect that every of the 4 files has a separate 'meaning', but in fact they are only split because of a previous limitation of the web-editor used.
To be explicit: These 4 files are processed as if they are 1 file, handled sequentially, if they exist.

As TD-er explained, there is (quite) some optimization/caching performed on the rules, more extensively on ESP32 platform because of less limitations in memory-use.

Re: Rules: only one "On System#Boot do" !?

Posted: 02 Oct 2022, 13:17
by joost d
Very clear Ton en TD-er. Thanx. That confirms what I already thought based on what I've struggled with.

What Ton mentioned about the 4 Rulesets and what TD said with regard to handling the first hit. Shouldn't that be mentioned in the manual, for example in the chapter (system) events?

Re: Rules: only one "On System#Boot do" !?

Posted: 14 Oct 2022, 04:24
by budman1758
You seem to expect that every of the 4 files has a separate 'meaning', but in fact they are only split because of a previous limitation of the web-editor used.
To be explicit: These 4 files are processed as if they are 1 file, handled sequentially, if they exist.
So what exactly is the rule file size limit now? Specifically, on ESP32. If the new editor can handle bigger and the rules are parsed as if its only one file can a single rules file larger than the previous total of 4 separate files be edited in the web editor? Or a single file be uploaded via the tools page? I'm working on an irrigation controller and there is quite a bit of complexity to my rules and flows. Breaking the files up @ 2048 Max characters is kind of a pain sometimes. Inquiring minds would like to know. :D :D

Re: Rules: only one "On System#Boot do" !?

Posted: 14 Oct 2022, 07:38
by Ath
You can put all rules in a single file, if you want to, though when on ESP8266 that can easily cause memory issues, especially on fully 'populated' units (many memory-intensive tasks used), so splitting them somewhat evenly across files can be helpful.
On ESP32 there is much more memory available (often > 100 kB free), so loading a larger file isn't an issue. Even though the web editor can handle files > 2048 bytes quite easily, the warning is still there, mostly to alert ESP8266 users, but also to avoid getting very large rules as that may slow down the unit because of the processing-time.

Re: Rules: only one "On System#Boot do" !?

Posted: 14 Oct 2022, 07:48
by budman1758
That's good to know. Thanks.

Re: Rules: only one "On System#Boot do" !?

Posted: 14 Oct 2022, 11:24
by TD-er
Please don't use 100k rules files, as the ESP32 does cache the rules in memory ;) (on recent builds)

ESP8266 can also handle files > 2k as we now use some JavaScript to actually call the upload URL when saving the rules.
Before we used HTTP POST, which does seem to have some limit somewhere between 1.5k and 2k (not always the same limit)
That was the reason for this limit.

I have tested with rules files upto 8k and those worked just fine.

Not sure about the effect on speed when using either a single large file or 4 smaller files.
However, it does make sense to have the most frequently called rules blocks placed first in the 1st rules file.

Re: Rules: only one "On System#Boot do" !?

Posted: 14 Oct 2022, 17:47
by budman1758
TD-er wrote: 14 Oct 2022, 11:24 Please don't use 100k rules files, as the ESP32 does cache the rules in memory ;) (on recent builds)
Not to worry. Don't think I'm gonna get THAT big. :lol:

Re: Rules: only one "On System#Boot do" !?

Posted: 14 Oct 2022, 17:50
by TD-er
budman1758 wrote: 14 Oct 2022, 17:47
TD-er wrote: 14 Oct 2022, 11:24 Please don't use 100k rules files, as the ESP32 does cache the rules in memory ;) (on recent builds)
Not to worry. Don't think I'm gonna get THAT big. :lol:
Sure... ;)
Well as soon as you do, please let me know because then we obviously miss something in the rules :)