openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.58k forks source link

[Groovy] Documentation does not explain how to enable engine to parse groovy rules. #8951

Closed boc-tothefuture closed 3 years ago

boc-tothefuture commented 3 years ago

PR https://github.com/openhab/openhab-addons/pull/8772 added support for Groovy rules. However, it does not explain how to use this with file based rules.

Expectation: Groovy rules work the same as Python, JS, etc.

Actual: Rules do not appear to be processed (nor does the script engine appear to be loaded).

Steps:

  1. Install Openhab 3.0M2
  2. Start Openhab
  3. Set Logging
    • log:set TRACE jsr223
    • log:set TRACE org.openhab.core.automation
  4. Install binding
    • bundle:install file:///bundles/org.openhab.automation.groovyscripting/target/org.openhab.automation.groovyscripting-3.0.0-SNAPSHOT.jar
  5. Restart openhab
  6. mkdir -p conf/automation/jsr223/groovy/personal/
  7. Create hello.groovy inside personal directory with the following content
    import org.slf4j.LoggerFactory
    def log = LoggerFactory.getLogger("jsr223.groovy")
    log.info("Hello world from Groovy")
  8. Wait or restart openhab

Hello world from Groovy is not logged, not does the engine appear to be loaded by the ScriptEngineManager.

wborn commented 3 years ago

Yes adding more docs is still TODO so it's good to have an issue for this (see https://github.com/openhab/openhab-addons/pull/8772#issuecomment-711142955). :+1:

def log = LoggerFactory.getLogger("jsr223.groovy") log:set TRACE jsr223 Hello world from Groovy is not logged, not does the engine appear to be loaded by the ScriptEngineManager.

To see logging, try instead:

log:set TRACE jsr223.groovy

I used it the same way in my Hello World example in https://github.com/openhab/openhab-addons/pull/8772#issue-505004457.

boc-tothefuture commented 3 years ago

That didn't work.. I had to go into the user interface and install it that way. Does that do something different than a bundle:install ?

J-N-K commented 3 years ago

@boc-tothefuture the UI installs the feature. If you only install the bundle, dependencies are not installed (so it might work or not, depending on other installed features).

boc-tothefuture commented 3 years ago

Issue is that I did an install, but not a bundle start.. 🤦

boc-tothefuture commented 3 years ago

@wborn do you want to close this issue or leave it because more documentation is needed?