At the risk of hijacking the thread…I think part of his question (and mine) is “how can we find for ourselves the syntax of the language and the API of built in functions?”. The only thing I have found so far is a comment on the website that the language is Java-like. Examples can only take one so far.
The rules and scripting language is a Domain Specific Language (DSL) written on the Xbase programming language. Xbase is itself built on the Java Runtime Environment and therefore has access to Java libraries and classes, but Xbase is not any more Java like then Clojure is Java like.
The documentation for Xtend which is also built on Xbase is here and it is where the wiki directs users to look. However, be aware that openHAB uses a DSL that is based on Xbase. Therefore there are certain things you can do in Xtend that you cannot do within your rules or scripts, such as create your own classes or use the shorthand for creating lists and maps.
The easiest way I’ve found to figure out what you can and can’t do in rules is to use Designer. Designer is based on Eclipse and the wonderful <ctrl>-<space> key combo to see what can complete what you are typing is the most helpful.
In the original example, I would type now.get<ctrl>-<space> and a menu will pop up showing all of the methods on now that start with “get”. You can even just type now.<ctrl><space> and see all the methods in now. This also works for completing Item and Group names.
I agree that the documentation of the DSL is lacking and perhaps someday I’ll have time to start a page to document all the things that are different between it and Xtend. In the mean time, the Xtend documentation is the place to look.
And for the record, both the Scripts wiki page and the Rules wiki page give a high level outline of the syntax as well as pointing you to the Xtend documentation.
Same problems here, as a .Net Developer it’s pretty hard to find solutions based on the problem I have.
Big thanks to Rich, spreading out alot of knowledge and solutions.
It’s really not that easy without a good IDE and well documented programming language.
But it works! at most of the times
VSCode with the openHAB extension is as good as any ide I’ve ever used. It had syntax checking code completion and code snippets. And since it supports LSP, the exact same parser that OH uses to lead the files is what VSCode uses to check the syntax.
Keep in mind that the above was posted over three years ago. A lot has changed since then.
If I’m talking about Wiki pages this is something posted years ago in reference to OH 1.x.
At that time when I posted the above, Scripts were (and are) a way to write a little chunk of callable Rules DSL code in another file. It still uses Rules DSL syntax. So your Rules link applies to both Rules and Scripts.
And in OH 2, we now have the Experimental Next Gen Rules Engine which will let you write Rules in PaperUI using any of the JSR223 languages (hopefully). But take note of the “experimental” in the name. It’s not yet ready for prime time. Documentation doesn’t really exist yet but I’ve started work on them here: Experimental Next-Gen Rules Engine Documentation 1 of : Introduction