Is usually tend to nest IF ELSE statements, but for readability this is a lot more complicated.
Have you thought about drawing a state diagram and from that to create a state machine?
That helped me with my garden irrigation.
On the other hand instead of
if (condition_a and condition_b and condition_c...)
i’m no using sometimes:
to stop the rule at that position.
It improves readability quite a lot especially when the alternative would be having nested IF statements
Is a good tutorial for a pretty comprehensive approach.
Design Pattern: How to Structure a Rule provides some help perhaps for dealing with the nested if/elses. For example, you can check for Holiday or Vacation mode up front and exit the Rule which eliminates one set of nesting.
But until you can build up the state machine and fully understand what you want to have happen for all of your conditions then you will never be able to build the code. So maybe draw a state diagram (see A State Machine Primer with HABlladin, the openHAB Genie and Washing Machine State Machine for examples) to map out all the conditions and appropriate states. Once it is all mapped out your Rule will be a bunch of same level if/else statements or switch statements.
This is the standard approach to a problem like this in programming.
THX! I’ve checked out both articles. In fact, my current implementation is a mixture from both patterns. So obviously there seems to be no way to create a better solution using openHAB.
I’ll think about storing the configuration in an external file and building a generic implementation, so that I only have to change the config file and not the code. Maybe with this approach I can stop writing duplicated code…