Imports in rules (dsl)

I’m migrating from openHAB 2.2 to openHAB 4.x. How to migrate the rules:
Where is the right place for import statements?

I tried this one:

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: 
      command: ""
    type: core.ItemCommandTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    label: testRule
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: |-
        import java.net.URI

        // erstmal nix
        logInfo("test-regel", "Meine Regel wurde aufgerufen.");
    type: script.ScriptAction

Another problem: Has the api changed?
in 2.2 i used: org.eclipse.smarthome.core

Is “org.openhab.core” the new one?
Where can i find an api documentation?

Best regards
Daniel

Nowhere. You can only import a class outside the rule and with managed rules (i.e. those defined in the UI) there is no outside the rule to put the imports.

You’ll just have to use the full class name without the import (i.e. where ever you use URI replace that with java.net.URI. Or keep these rules in .rules files. Or look into one of the other rules languages.

I do want to emphasize that there is no requirement to move rules from files to become managed (e.g. defined in the UI). I also want to encourage you to consider eventually looking into on of the other rules languages. If you are messing around with raw URI Objects in your rules, you are likely stretching Rules DSL to it’s limit. You might find a much better environment in JS Scripting or jRuby or even Blockly.

Absolutely. That happened years ago in OH 3 and was a large reason why there even was an OH 3 at that time.

Definitely review the announcements and list of breaking changes for every version of OH between OH 2.2 and 4.1. A lot has changed in the approaching six years since OH 2.2 was released. There is no unified "breaking changes since OH 2.2). You’ll have to work through all the announcements to find all those changes that are relevant to you.

Do not skip the Getting Started Tutorial. That’s basically the OH 2.x to 3.x migration tutorial.

Yes. You can find them the same place it’s been since OH 2. Overview (openHAB Core 4.2.0-SNAPSHOT API)

1 Like

ah, ok! Thanks a lot! I created everything else from scratch.
Perhaps i will rewrite the rules, too. JS or Blockly.