Groovy Scripting

I’ve installed the Groovy scripting plugin in version 3.2.0

When I try to create a rule, I get to this screen;


I was expecting to see Groovy as choice here. I assume I’m not understanding this correctly. What is the process for doing this?

Not many are using Groovy and I’m not 100% certain it can be used in UI rules in the first place. Not all of the automation add-on support UI rules.

The docs seem to suggest it does. They also say “Groovy scripts provide access to almost all the functionality in an openHAB runtime environment”. So seems worth looking at. It’s the most “Java-esk” of the scripting languages, so I’d like to give it a shot.

Just can’t seem to get started.

@rlkoshak … ah… figured it. it was running with JDK 17. Switch to 11 and the other scripting languages appeared!!!

The JScript add-on is Java. If that’s what you are after you might look at that add-on if Java is what your are after.

I thought JScript was javascript. Which, despite the name, is not really Java. However, Groovy is far closer to Java and more like Java+ in way. You can actually write code pretty much in Java and Groovy will run it. You can then expand on it to write it more groovy way (shortcuts). but normal Java style pretty much works, so I think coming from Java it’s a much better choice then JS.

Is there is demo of this anywhere? even from the plugin developer? It’s looks like the editor that comes up has some kind of code complete in, but I could see how it worked.

Some basic examples of how to reference Things and Items from groovy would be a good starting point. I just need a bit of a kick starts, I think.

A little bit further down the list from the Groovy plugin:

Forum post here

There’s another Java rules system available from this external repo:

Thanks, I did see that too.

But the groovy one looks a little more integrated, if only I could get an example of how it worked!! :slight_smile:

I might look at the too, but I’d at least like to get a handle on how the Groovy one works and it’s part of the core OH3 addons.

Something really simply like, checking the state on an Item to set another, should be enough to get me going.

But if I can’t get anywhere with the Groovy one, which would be disappointing, that’s my next stop.

I’m fully aware. I’m referring to JRule - openHAB Rules using Java ( got the name wrong), not JavaScript Scripting - Automation | openHAB.

A very few users actually use Groovy and none have contributed to the docs nor provided any examples so :man_shrugging: . Assuming you know Groovy you can probably get by from JSR223 Scripting | openHAB and the OH javadocs themselves: Overview (openHAB Core 3.3.0-SNAPSHOT API). Looking at Jython and Nashorn JS examples can help too since most of the interactions with OH itself are done through Java Objects which will work the same no matter the language. For example, commanding Item Foo to ON would be:

events.sendCommand("Foo", "ON"); // Nashorn JavaScript
events.sendCommand("Foo", "ON") # Jython

You should see all about events and the other stuff that gets injected into a Rule when it runs on the link above and since it’s a Java Object should work about the same, just use Groovy syntax for calling the function.

Helper libraries were never written and for the most part I don’t think it supports external libraries very easily anyway. So it’s there, it’s been there for years, but the people who use it seem to keep to themselves and not publish much in terms of examples, docs, or tutorials.