Is it possible to import items inside items or rules inside rules?

Hi,

I have a quite simple question: Is it possible to import items inside items or rules inside rules?

If you are used to modular programming, you would like to create your own project structure here. It is possible to write many rules or items in a separate file, but these are not logically assigned.

In addition, you quickly have a lot of items or rules in one folder. I would like to use a subfolder for this, so that you can achieve the following structure:

/items
  /myItem1
    mySubItem1.item
    mySubItem2.item
  /myItem3
    mySubItem1.item
  myItem1.item
  myItem2.item
  myItem3.item

Insinde myItem1.item and myItem3.item I want to import from their specific subfolder.

Small and clear groups can come into a file. But occasionally you have groupings that are really large and elaborate. Then the code is hard to read. That’s where an import would come in useful. Is there a good possibility? Of course I can split the files individually, but then on the one hand the logical assignment is missing and on the other hand only more files would arise and this folder would become unclear. Therefore, it would be very practical in large projects, as described.

You tagged this for openHAB2. Please note that we are close to openHAB3 release, so no more enhancements for oh2.
Nevertheless, this was already discussed in the past and denied. It would cause folderObserver to use too much resources.

Just to add a little bit more around Hans-Jörg’s answer.

Items

.items files are flat. There is no need to import a .items files into another one because anything defined in one .items file can only be defined once anyway. So what you are really after here is subfolders which, as mentioned, it was determined would not be supported by the developers.

Rules

The Rules DSL does not support imports of other Rules files. We can’t create Rules DSL libraries (which is what you are really asking about). However, Groovy, JavaScript, and Jython do not have this limitation and all of these languages are (or will) be supported in both OH 2.5 (through installation of the NGRE) and OH 3 (through installation of language addons, JavaScript is supported by default). These other languages support both importing libraries and structuring your code into subfolders.

And, with Rules DSL, there are other ways to avoid needing to have duplicated code. See Design Pattern: DRY, How Not to Repeat Yourself in Rules DSL.