Multiple Rules Files run now without Problems?

Hey Board…

I wan’t to create multiple Rule files, only in this case i will have the Overview.I read on a Google board there are problems with running Multiple Rule Files …

So, is it now possible (without problems) to run multiple Rule Files?

my source!category-topic/openhab/rules/jmH3ZaixP6w

I am using openHAB 1.7.1 with the following setup:

16 items files
15 rules files
13 sitemap files

This setup seems to work fine. I have had many problems that I thought was related to the “multiple rules files”-issue, but they all turned out to the caused by other problems - most of them with myself as root cause, :smile:

1 Like

Hey Kjetil

Thanks for your Feedback … can you tell me how you have add multiple rules Files ? Or load OpenHAB all automatic ?

Thanks for your Feedback !

OpenHAB is regularily scanning all the sub-folders below the Configuration folder and detects changes, i.e. updated files, new files or removed files.

This means that you can create or modify files as you like, and openHAB will load them and start using them as soon as the changes are detected.

1 Like

Hey …

Thanks again :smiley: cool … i will test it asap … Hope i don’t get any Problems !

You might run into two problems, one is a side effect and the other is a bug.

The side effect is that openHAB loads all your files in parallel. This can cause a situation where your rules files are loaded before the items files that defines the items the rules work on are not yet loaded. So if you have System started rules or events that occur while the files are loading you will get Undefined errors. Another issue is if you are dependent on the historic state but your rules load before persistence you can see null pointer errors. You can solve this by changing the polling period at the top of openhab.cfg so that items get loaded first and rules get loaded last. I put five seconds between each (i.e. each ois five seconds longer) but your timing will depend on your system.

The second problem may hit once in a blue moon. Sometimes when loading the rules files it hits a bug which causes a FileNotFoundException and each subsequent rules file will also generate an error instead of being loaded. There are elaborate work arounds but I personally just make sure to watch the logs whenever I restart openHAB and touch the rules files if the error shows up. Touching the files will cause openHAB to reload them and they always successfully load the second time around.

In the almost year I’ve been running openHAB, I’ve seen this error three times.

1 Like

I should have been a bit clearer. I am saying that I am not seeing any problems with my setup these days, but that is not the same as saying that there are no potential problems lurking in the shadows, :smile:

I know this has been discussed a lot in the forum, and it is not clear to me if something has been done towards having a more deterministic startup of openHAB.

In my setup (openHAB 1.7.1 with default settings for the “file observer”), however, I am consistently seeing the following order of loading files:

  1. sitemaps
  2. persist
  3. items
  4. rules

I am aware of this possible problem, but I have only seen it once in all my time of running openHAB.

Anyway, thanks for providing additional information on this @rlkoshak. It is always better to know about the possible pitfalls upfront.

It is highly unlikely to be addressed in OH1. I know that OH2 is moving towards even more file separation so perhaps it is either more deterministic or robust to them loading out of order.

Depending on the number of files and how quickly your machine is able to load the files you may never see them being loaded all out of order. However I know that at least in my case, running on a laptop with a dual quad core intel i7 processor (old though it may be) has enough oomph to load a bunch of the files at the same time and if I don’t monkey with the poll times they get loaded in all sorts of different orders.

This is probably way overkill, I haven’t experimented with the minimum values but this is what I run with:


I’ve only seen it a few times after hundreds of restarts over the past year. It is exceptionally rare but knowing what the cause is can save a lot of time and screaming when/if it ever does happen to you.

1 Like

What about a rule file that contain multiple rules, do they run in parallel?

All rules run in parallel. Whether or not they are defined in separate files is irrelevant.

1 Like

Please point me to the location of openhab.cfg or equivalent file. I have openHabian v 2.3.0.
For some reason, I could not find such a file on my system. Thanks.

There isn’t such a file in OH2

Ok. So how do I adjust the polling period in OH2 so that items files are loaded before rules files at startup? Thanks.

You can’t.
But if your problem is related to persistence (restore on startup) you may use a workaround:

Info only - there is a long-term push to improve this area of OH2 startup, but a quick fix is not likely to appear just yet.

1 Like