Note that what Sebastian is recommending is HABApp. This is a separate service that runs along side openHAB and provides pure Python 3 rules support. It interacts with openHAB through its REST API. It is not the same thing as the embedded Jython rules.
The only real advantage of going the Jython route over JavaScript is that the Helper Libraries are more mature for Jython at this time, though work is being done to bring the JavaScript version up to the same level. Beyond that, whether you are using Rules DSL, JavaScript, Jython or the experimental jRuby rules languages, basically what you are doing is scripting together some logic around interactions with openHAB (updating Items, getting the state of an Item, calling actions, creating Timers, etc.). All of these interactions with openHAB are taking place through Java Classes and Objects. So, for the most part, rules from one language to the next will work and look largely the same, just with slightly different syntax (jRuby is a bit more different from the others though).
So, to create a Timer in Rules DSL you’ll have:
createTimer(now.plusMinutes(5), [ |
// do something
])
and in Jython it will be
from org.openhab.core.model.actions import ScriptExecution
from java.time import ZonedDateTime
def runme():
// do something
ScriptExecution.createTimer(ZonedDateTime.now().plusMinutes(5), lambda: runme())
and in JavaScript it will be
var ScriptExecution = Java.type("org.openhab.core.model.actions.ScriptExecution");
var ZoneDateTime = Java.type("java.time.ZonedDateTime");
var runme = function(){
// do something
};
ScriptExecution.createTimer(ZonedDateTime.now().plusMinutes(5), runme);
NOTE: I just typed in the above, there are likely errors.
Except for the fact that Rules DSL already automatically imports a bunch of stuff for you (as well as a lot of other “magic”) they are very much the same.
Here’s another example:
MyItem.sendCommand(ON) // Rules DSL
events.sendCommand("MyItem", "ON") # Python
events.sendCommand("MyItem", "ON") // JavaScript
I can’t imagine why. If you choose not to use JavaScript as a rules language you will not need to know JavaScript for anything else.
While there is a little bit of work going on to be able to write rules in Java, that is not ready for prime time and more experimental than jRuby support right now. To be clear, in OH 3.1 M3 and before the only officially supported built in languages (i.e. those that come with OH by default or can be installed via an add-on through MainUI) are Rules DSL (which is a dialect of Xtend), Jython 2.7, Nashorn JavaScript (ECMAScript 5.1), and Groovy (which I’m told is actually the closes to Java among the four). And in all of these languages, all interactions with openHAB itself will be done through Java Classes and Objects, but the syntax is very different from Java, since they are actually not Java.
In general it’s recommended against using more than one way to do something, but I see no down side to using more than one language in rules beyond the extra mental load it takes to read and understand multiple languages at the same time.
Edit: There were indeed typos