JRule - openHAB Rules using Java

Strange. And after a full openhab restart?

There is a sample user project here using Maven as build tool, but not anything specific for your choice of editor: GitHub - seaside1/jrule-user: JRule User Demo and Test Project - but I suspect it might not be fully up2date. @Seaside can confirm

It’s on my big todo list :frowning: . But yes you should still be able to use it as a guidline for setting it up.

I am back on trying to get this to work now.
I am on a Debian machine, and installed OpenHab 4.1.2 via package. No Docker or other containers on the machine.

I normally watch the logs via openhab-cli log:tail.
I have done a service openhab restart, and get

11:23:54.870 [INFO ] [.internal.events.JRuleEventSubscriber] - [JRuleSubscriber] Event processing paused, queueing event Item 'gHumidity' changed from 64.4 to 64.5 through statusHumidity_CCSW

If I restart the bundle via bundle:restart 405, which I assume is the correct incantation where 405 is

405 │ Active │  80 │ 4.0.0.202404081933     │ openHAB Add-ons :: Bundles :: Standalone Java Rules Automation

I won’t get any JRule messages:

11:28:55.335 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'statusHumidity_CCSW' changed from 71 to 70
11:28:55.337 [INFO ] [nhab.event.GroupItemStateChangedEvent] - Item 'gHumidity' changed from 64.5 to 64.4 through statusHumidity_CCSW
11:30:11.251 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'statusTemperature_CCN1' changed from 77 °F to 76 °F

I am suspecting I’m missing some dependencies.

… tracking down why this isn’t getting called:


    @Nullable
    private synchronized Boolean compileAndReloadRules() {
        eventSubscriber.pauseEventDelivery();
        compiler.compileRules();
        JRuleEngine.get().reset();
        createRuleInstances();
        logInfo("JRule Engine Rules Reloaded! {}", JRuleEngine.get().getRuleLoadingStatistics());
        eventSubscriber.resumeEventDelivery();
        return true;
    }

Turned up debugging

2024-05-09 12:04:16.637 [DEBUG] [internal.events.JRuleEventSubscriber] - [+JRuleSubscriber+] Received event 'ItemStateEvent' with topic 'openhab/items/statusHumidity_CCNW/state' and payload '{"type":"Decimal","value":"66"}'
2024-05-09 12:04:16.639 [DEBUG] [on.jrule.internal.engine.JRuleEngine] - [+JRuleEngine+] watching for item: 'statusHumidity_CCNW'? -> false
2

restarting the bundle, it looks like the class reloading doesn’t complete

12:07:03.784 [INFO ] [jrule.internal.compiler.JRuleCompiler] - [JRuleCompiler] Number of classes to load in to memory: 1 folder: /etc/openhab/automation/jrule/rules
12:07:03.785 [DEBUG] [jrule.internal.compiler.JRuleCompiler] - [+JRuleCompiler+] Attempting to load class: org.openhab.automation.jrule.rules.user.BkmTest
12:07:15.875 [DEBUG] [.internal.events.JRuleEventSubscriber] - [+JRuleSubscriber+] Received event 'ItemStateEvent' with topic 'openhab/items/statusHumidity_SSSE/state' and payload '{"type":"Decimal","value":"60"}'
12:07:15.876 [DEBUG] [ion.jrule.internal.engine.JRuleEngine] - [+JRuleEngine+] watching for item: 'statusHumidity_SSSE'? -> false

Maybe a problem with OSGI?

14:24:56.795 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory] : Dependency Manager created osgi.ds.satisfying.conditioninterface=org.osgi.service.condition.Condition, filter=(osgi.condition.id=true), policy=dynamic, cardinality=1..1, bind=null, unbind=null, updated=null, field=null, field-option=null, collection-type=null, parameter=null
14:24:56.800 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory] : Component created: DS=DS14, implementation=org.openhab.automation.jrule.internal.JRuleFactory, immediate=true, default-enabled=true, factory=null, configuration-policy=optional, activate=activate, deactivate=dispose, modified=null configuration-pid=[automation.jrule]
14:24:56.800 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory] : Component Properties: {osgi.ds.satisfying.condition.target=(osgi.condition.id=true)}
14:24:56.800 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory] : Querying state disabled
14:24:56.801 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory] : Querying state disabled
14:24:56.801 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory] : Component can not be activated since it is in state disabled
14:24:56.801 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory] : Querying state disabled
14:24:56.801 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : Updating target filters
14:24:56.802 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : No change in target property for dependency $001: currently registered: false
14:24:56.802 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] :  No existing service listener to unregister for dependency $001
14:24:56.802 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : Setting target property for dependency $001 to null
14:24:56.803 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : New service tracker for $001, initial active: false, previous references: {}, classFilter: (objectClass=org.openhab.automation.jrule.internal.events.JRuleEventSubscriber), initialReferenceFilter (objectClass=org.openhab.automation.jrule.internal.events.JRuleEventSubscriber)
14:24:56.803 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : dm $001 tracker reset (closed)
14:24:56.804 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : dm $001 tracker opened
14:24:56.804 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : registering service listener for dependency $001
14:24:56.804 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : No change in target property for dependency $002: currently registered: false
14:24:56.804 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] :  No existing service listener to unregister for dependency $002
14:24:56.805 [DEBUG] [utomation.jrule.internal.JRuleFactory] - bundle org.openhab.automation.jrule:4.0.0.202404081933 (405)[org.openhab.automation.jrule.internal.JRuleFactory(446)] : Setting target property for dependency $002 to null

I see the same.

If you’re able to add some logging statements to JRule in the class loading section and/or connect a debugger we might find the culprit and can issue a fix :slight_smile:

I can do that, I need to set up some infrastructure. I’m deploying this instance over SSHFS. What I need to do is upgrade my home OH to the latest and debug locally.

I have never looked, but I assume there’s a howto for developers, or on how to debug a plugin. OR, can I just upload the JAR and attach a debugger to that instance?

Development is easiest done on a local test instance. Just clone the repo, build the project (mvn clean verify), then copy the resulting jar file into the local addons folder.

Run OH with ./start_debug.sh or similar, then connect your debugger. I’ve probably forgotten a step or three, but it is fairly straight foward :innocent:

Understood. I will get around to this, but I fear that I won’t be able to duplicate the problem on my workstation.