Groovy with Eclipse

I played a bit with Eclipse and Groovy, and I liked that it makes it possible to remote debug Groovy scripts running in openHAB.

There are some steps to set it up, so that the openHAB classes can be accessed via Maven dependencies and a script shows no dependency errors.

I used the Groovy rule script from JSR223 Scripting.
Groovy automation should be set up and the script working.

Install the latest Groovy Eclipse Plugin as given in

→ Releases
Main Package + Maven Support

Create a project folder OHRules in the openHAB addons sources folder, so the relativ dependencies work.
Copy the pom from MQTT addon and change artefactid and add version.

In Eclipse create a new Groovy Project located in this OHRules folder.

Project - Link source (for me a Samba share to my openHAB test installation on a FreeBSD server: O:\test\openhab-3.1.0\conf\automation\jsr223)
This appears in the project as jsr223 folder containing the script.

Project - Properties - Project Natures - add Maven Nature to get Maven support (need it to get the openHAB dependencies)
Maven - Update Project
Now the openHAB Maven Dependencies show in the project.

With the Maven dependencies working, F3 on SimpleRule jumps to its Java source.

If openHAB is run with debug Groovy scripts can be remote-debugged.

Add a breakpoint to the script, create a new Debug configuration, connect it, add a blank somewhere in the script and save to trigger it and the debugger should get activated. Variables can be inspected.

So I found out addon actions can be run like

def a = actions.get(“mqtt”,“mqtt:broker:id”)
a.publishMQTT(“atopic/test”,“a groovy hello”)


Thanks for posting this tutorial! Groovy is one of the least mentioned rules languages un OH so I’m always very happy to see new tutorials.

Having said that, I’ve move this to the Tutorials and Solutions category so it’ easier for people to find.

1 Like