Hi guys,
would like to ask few questions about rules engine, just to understand what is better in performance (memory etc)
is it better to have as less as possible rules or number of rules doesnt matter?
for example, is it bad to have simple rules like
when item 1 changed to ON
then
do something
end
And then another rule when item OFF do something else. Is it better to have one rule when item 1 changed, then if =ON do X, else if =OFF do Y. ?
if I have routines that can be triggered by 2 different ways, lets say physical button and virtual button for sleep routine. Is it better to have all the same repeated commands in both rules (switch off this, that and the other) or is it better to define such routine in 1 place, and then the other rule just says, if they press physical Sleep button, switch on VirtualSleep button (and he then executed the commands)
In that case, one rule would trigger another rule. And in first case, each rule would have all the commands it needs, what is better optimized in general?
Just to elaborate on Marcusā very correct answer, almost never does performance like discussed matter in a home automation context. Even an RPi is plenty powerful enough to process most events and most rules in < 200 msec which is plenty fast enough for home automation. Therefore what really matters is your optimization and performance.
What is easier to write? More importantly, what is easier to understand? Most importantly, what is easiest to maintain in the long run? That is the performance that you need to be concerned about.
Given thatās the case, you will want to apply DRY: Do Not Repeat Yourself. You should almost never have blocks of code that repeat, be they slight modifications on what to do in a big switch statement or a bunch of rules that do something slightly differently. Duplicated code means X times more work later on if you have to change something.
Finally ā¦
This implies a lack of understanding about how rules actually work. Why have two rules with one that calls the other? Why not just the one rule that triggers by either event? openHAB is an event based system. Any given rule can be triggered by any number of different events.
Hello and thank you for the meaningful explanations. Iām learning OpenHAB3, Iām trying to write rules, not everything works out ā¦ How to delete unnecessary rules?
Just tested the removal on my system, working ( no question by system)! That is for a rule created via the MainUI, if you try to remove a rule that is created from a (old?) .rules file it migth
be different and not even possible that way.