OH1: split .rules file; location of includes?

Still in OH1 with a rule file that has 1,200 lines – too much scrolling for my liking.
Hence, I want to split the single .rules file.

Do I need to include the includes in each rule file?
Or only once?
How would OH know where to look for these, if the .rules files are not loaded in order (whatever the order might be) – as in load the rules file with the include statements first?

This is what I mean by includes:

import org.openhab.core.library.types.*
import org.openhab.core.library.items.*
import org.openhab.core.types.*
import org.openhab.core.items.*

Also, OH1 changes the file properties, which I correct in the rules file like so:

rule "file permissions"
    System started
    var String results = executeCommandLine("sudo chmod -R 775 /etc/openhab/", 5000)
    logInfo("BootStrap1.rule", "Resetting permissions on /etc/openhab/: " + results)
    results = executeCommandLine("sudo chmod -R 775 /usr/share/openhab/", 5000)
    logInfo("BootStrap2.rule", "Resetting permissions on chmod -R 775 /usr/share/openhab/: " + results)

However, OH will only reload the rule file that has changed. this means most of the time, this code will not be executed.

Does it look like I am creating more of a headache for me with multiple .rules files, instead of having only one?

When you split your rule file, you will need to add the imports in all the new rule files where whatever you import today is needed.

I think the key thing to understand is that there is absolutley no relationship/association/tie between rules files - apart from what is shared through items states.

This also means that the code you have for file permissions needs to be duplicated to all the rules files.

Note that the “System started” trigger condition is, IMO, named a bit misleading since it triggers on loading of the file (something that apparently was once considered to happen at system startup, but as we all know actually happens every time you modify a file).

Hard to say. Generally I like to split things into multiple files - if I can find a set of rules that naturally belong together but at the same time naturally does not belong together with some other set of rules.

1 Like