JRule - OpenHAB Rules using Java

Oh yes, that’s exactly the same “issue” I have.

Added BETA8 Build:




  • Optimized items by gerrieg https://github.com/seaside1/jrule/pull/33
  • Syntax change: event.getValue(), event.getValuesAsDouble() etc replaced with event.getState().getValue() and event.getState().getValueAsDouble()
  • Syntax change JRuleSwitchItem.sendCommand(myItem, ON) replaced with JRuleSwitchItem.forName(myItem).sendCommand(ON)
1 Like

I’ve got several Contact items which are sometimes out of reach. In this case, JRule throws an IllegalArgumentException when trying to access the state:

var ct = JRuleItemRegistry.get("GN_CT_DOOR", JRuleContactItem.class)

This is the Exception:

2022-05-14 11:40:12.269 [ERROR] [on.jrule.internal.engine.JRuleEngine] - [UpdateDisplayHall] Error message: No enum constant org.openhab.core.library.types.OpenClosedType.NULL
2022-05-14 11:40:12.273 [ERROR] [on.jrule.internal.engine.JRuleEngine] - [UpdateDisplayHall] Error Stacktrace: java.lang.IllegalArgumentException: No enum constant org.openhab.core.library.types.OpenClosedType.NULL
	at java.base/java.lang.Enum.valueOf(Enum.java:240)
	at org.openhab.core.library.types.OpenClosedType.valueOf(OpenClosedType.java:1)
	at org.openhab.automation.jrule.internal.handler.JRuleEventHandler.getOpenClosedValueFromState(JRuleEventHandler.java:276)
	at org.openhab.automation.jrule.internal.handler.JRuleEventHandler.getOpenClosedValue(JRuleEventHandler.java:241)
	at org.openhab.automation.jrule.items.JRuleContactItem.getState(JRuleContactItem.java:37)
	at org.openhab.automation.jrule.rules.user.DisplayHallRule.lambda$updateDisplayHall$0(DisplayHallRule.java:90)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.openhab.automation.jrule.rules.user.DisplayHallRule.updateDisplayHall(DisplayHallRule.java:83)

It would be nicer to get UNDEF in this case.

trying to use transform leads to an Exception

final var dayInfo = transform("MAP(DayOfWeek_de.map):%s", dayOfWeek.name());


2022-05-14 13:01:08.253 [INFO ] [rule.internal.compiler.JRuleCompiler] - [JRuleCompiler] Error on line 54 in file:///etc/openhab/automation/jrule/rules/org/openhab/automation/jrule/rules/user/DateRule.java: cannot access org.openhab.core.transform.TransformationException
  class file for org.openhab.core.transform.TransformationException not found

I have created a fix for this. Have not tested it yet. Will build a new version soon.
See Fixed issued with undef item for state · seaside1/jrule@6827940 · GitHub

1 Like

This is fixed by seime: See: Wrap TransformationException in JRuleExecutionException by seime · Pull Request #39 · seaside1/jrule · GitHub

1 Like

This engine and the support/dedication it gets is awesome.

I’ve reimplemented my 250+ items/50+ rules openHAB 2.5 system with JRule on openHAB 3.2 within 6 hours. Some rules are really complex, but it was really easy to do a 1:1 migration from JSR223 groovy/jython and xtext rules.

Thanks to static typing, I could realize a long-postponed “rename items for more consistency” project without any problems.
Using IntelliJ and gradle instead of VSCode or the openHAB UI for editing really helps a lot.

For me, this is by far the best rule engine available in openHAB since openHAB 1.8.


It is fantastic to see that several people are contributing to the project. :+1:


Built a BETA11



I have added a template project for building and deploying rules using maven.
In that example project there is also code for testing your rules with a fake eventbus.
see: GitHub - seaside1/jrule-user: JRule User Demo and Test Project