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

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
joost d
Normal user
Posts: 53
Joined: 24 Dec 2020, 17:55
Location: Netherlands/ Haarlem

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

#1 Post by joost d » 02 Oct 2022, 11:12

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?

TD-er
Core team member
Posts: 8642
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#2 Post by TD-er » 02 Oct 2022, 11:40

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 :)

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

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

#3 Post by Ath » 02 Oct 2022, 12:53

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.
/Ton (PayPal.me)

joost d
Normal user
Posts: 53
Joined: 24 Dec 2020, 17:55
Location: Netherlands/ Haarlem

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

#4 Post by joost d » 02 Oct 2022, 13:17

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?

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

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

#5 Post by budman1758 » 14 Oct 2022, 04:24

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
"The glass is twice as big as it needs to be".

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

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

#6 Post by Ath » 14 Oct 2022, 07:38

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.
/Ton (PayPal.me)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

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

#7 Post by budman1758 » 14 Oct 2022, 07:48

That's good to know. Thanks.
"The glass is twice as big as it needs to be".

TD-er
Core team member
Posts: 8642
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#8 Post by TD-er » 14 Oct 2022, 11:24

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.

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

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

#9 Post by budman1758 » 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:
"The glass is twice as big as it needs to be".

TD-er
Core team member
Posts: 8642
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#10 Post by TD-er » 14 Oct 2022, 17:50

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 :)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 20 guests