Rules: Few encompassing rules or mutilpe single rules

For execution purposes is it better to write complex rules to handle multiple task like one rule to handle all of your lighting needs? Or write several simple rules like one rule for each light you want to control or each reason you want to control a group of lights?

I don’t think it makes much difference from an execution standpoint, so I’d recommend doing what makes the most sense for you conceptually. Often, that ends up being a mix of both.

If you have a group of switches that you always turn on together, then that’s a sensible rule that can be used on its own. Then you can have a complex rule that triggers the first rule as needed.

For example, I have a rule that triggers whenever my living room light switch is turned on, which turns on some other switches (depending on the time of day). I also have a rule to turn my HVAC and lights on when I arrive home. All the second rule has to do is send a command to my living room lights to trigger the first rule.

In contrast, my bedtime rule turns my bedroom/bathroom lights on and then turns other lights off sequentially with a 0.5-second delay between each one (so that they turn off behind me as I walk toward my bedroom). I only use this particular lighting sequence for bedtime, so it’s all done in a single rule.

Another way to look at this is avoiding duplication. If you’re doing the exact same thing in multiple rules, then one can probably just call the other. If you modify your code later, you’ll have a much easier time.

There is no hard and fast rule.

From an execution perspective it probably doesn’t matter, though there are some things that will work better from one single rule and other things that will work better spread across multiple rules.

What is of paramount importance though is your audience. You may not think about code this way, but code definitely has an audience, and the computer running the code is only one member of that audience, and not even the most important member of that audience.

In the context of OH rules, future @jjennings308 is the most important audience. Will that poor soul be able to read and understand these rules a couple years from now and be able to maintain and update them? This is what should drive the overall structure of your rules. If it makes more sense to you to split them into multiple rules, do that. If it makes more sense to put it in one larger rule, do that.

But keep in mind that rules are event driven. It’s often most efficient from the computer’s perspective and most understandable from the human’s perspective to have one rule that runs given a specific event and conditions. It probably doesn’t make a whole lot of sense to have multiple rules running at the same time triggered by the same event and conditions.