Contact item and Number item do not trigger rule in oh2.3.0

  • Platform information:
    • Hardware: rpi2
    • OS: raspbian
    • Java Runtime Environment: 8
    • openHAB version: 2.3.0

Just a question: is there anybody not having problems in OH 2.3.0 with triggers? In my setup (https://github.com/cvdenzen/etc_openhab2, branch develop) only the time (cron) triggers seem to work. And every now and then (after a restart of openhab) the pir_gf_achterdeur17 triggers a rule.
The pir sensor is working very reliably, as I can see in the Openhab GUI and in the karaf logging:

22:42:50.340 [INFO ] [smarthome.event.ItemStateChangedEvent] - LichtIntensiteit_Woonkamer changed from 2.2916665 to 2.5
22:43:00.351 [INFO ] [smarthome.event.ItemStateChangedEvent] - LichtIntensiteit_Woonkamer changed from 2.5 to 2.2916665
22:43:25.257 [INFO ] [smarthome.event.ItemStateChangedEvent] - pir_gf_achterdeur17 changed from OPEN to CLOSED
22:43:33.634 [INFO ] [smarthome.event.ItemStateChangedEvent] - pir_gf_achterdeur17 changed from CLOSED to OPEN
22:43:38.976 [INFO ] [smarthome.event.ItemStateChangedEvent] - pir_gf_achterdeur17 changed from OPEN to CLOSED
22:43:46.478 [INFO ] [smarthome.event.ItemStateChangedEvent] - pir_gf_achterdeur17 changed from CLOSED to OPEN
22:44:00.338 [INFO ] [smarthome.event.ItemStateChangedEvent] - LichtIntensiteit_Woonkamer changed from 2.2916665 to 2.5
22:44:10.346 [INFO ] [smarthome.event.ItemStateChangedEvent] - LichtIntensiteit_Woonkamer changed from 2.5 to 2.2916665
22:44:20.346 [INFO ] [smarthome.event.ItemStateChangedEvent] - LichtIntensiteit_Woonkamer changed from 2.2916665 to 2.5

No that’s working reliably.
Maybe your rule file has a syntax error ? In that case it does not get compiled.
Assume you’ve properly enabled logging, you should see entries like this in openhab.log:
2018-09-20 22:58:18.618 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'Test.rules' has errors, therefore ignoring it: [104,9]: no viable alternative at input 'tem'

You did not mention the binding nor its configuration…

There are two thread pools that Rules execute in. Cron triggered Rules run from one thread pool and event triggered Rules trigger from a different thread pool.

When I see “only the time (cron) triggers seem to work” I immediately suspect that you have used up the event triggered pool. See Why have my Rules stopped running? Why Thread::sleep is a bad idea.

By default, only 5 event triggered Rules can run at the same time. If you have long running Rules or Rules that never return then no other Rules can run.

Thanks for your reaction.
I have not seen error messages in the openhab.log. (earlier I had syntax errors in rule files, but I resolved them).

The fact that the cron triggers make the rule execute means that there is no problem with the rule.

Because the items gets updated (as I can be seen in the log and in the GUI) I didn’t think it was important to mention the binding. I use the mqtt binding. The mqtt messages are created by a custom (self-written) osgi bundle. The source can be found at github. The configuration can also be found at github (the link in my original post).

Hello Rich,

This is very interesting information. I will try to investigate my rules and report the results!

Hello Rich,

I found (again) some strange things in the Openhab 2.3.0 rules magic. logDebug does not log, even after the command log:set DEBUG. Other log messages on this level are shown with log:display, but the rules logDebug messages are not shown.
Another thing is that the rules engine complains about something not being an Item or being null. I don’t understand and I have come to a point that I don’t want to understand it.
I tried to move to Javascript jsr223 engine, but the examples I found on github don’t work on OH 2.3 (ModuleBuilder not found, TriggerFactory not found).
My next step will be to try to write the rules in plain Java (in an osgi bundle). Is there a place where I can find any helpful information?

Did you set the proper log level ? org.eclipse.smarthome.script it would need to be.
Another explanation would be that your rule is broken (you’ve mentioned it has got errors), then OH will stop processing it and eventually never get to that logDebug command.

You’re giving up too soon.
Post your rule(s) here, and the item definition used in the rule(s).

I strongly advise not to. You will be completely on your own.

I don’t use logDebug much so I have no experience to draw upon. As Markus says, perhaps the configuration in the log4j2 config is overriding the setting in karaf.

Without code I can only guess but if venture to guess that you are trying to cast the state of an item whose state is NULL. Or you might be seeing a known timing bug where rules start executing before all your items have been loaded.

I don’t know who is keeping after JS, if anyone. Most of the users who use jsr223 use Jython with a small few using groovy. @illnesse, are you using JS JSR223 rules? Have any advice if so?

I too recommend against this. You will be completely on your own. At least consider using NodeRed for rules. There are many on this forum who do so and there is good integration been the two. Heck, NodeRed is even a choice to install through openHABian.

@cvdenzen re: jsr223, it’s totally worth pursuing, it’s not only the easiest to set up and maintain but the most straightforward option imo, these are some good starting points…

helper scripts for persistence, triggers, basic rule layout etc:

check out my set of rules, there’s a lot of goodies to start with, i’m using a modified version of lewie’s scripts above but it’s all in the repo:

Good luck, poke me if you need help!

Please show the rules, please show the errors. Copy and paste them as text here. Don’t forget to mark both rules and logs as “code” (just type ` three times in an extra row ahead and after the code:)
```

Your Code goes here

```

The fact, that only the time cron trigger works as expected means, that you have an issue with your triggers. It would be much more easy to find these issues when having a look to the code :wink:

@illnesse I will give Javascript a try. I am using openhab 2.3.0 stable. When I copy th openhab2_pub_001/00_jslib files and try a simple rule, I see this error:
Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/carl.js': ReferenceError: "TriggerBuilder" is not defined in /etc/openhab2/automation/jsr223/00_jslib/triggersAndConditions.js at line number 63

My guess is that you are running another version of openhab and that the api has changed.
My simple rule is:
‘use strict’;
load(’/etc/openhab2/automation/jsr223/00_jslib/JSRule.js’);

JSRule({
	    name: "MotionSensor",
	    description: "Line: "+__LINE__,
	    triggers: [
		            ItemStateChangeTrigger("pir_gf_achterdeur17")
		        ],
	    execute: function( module, input)
	    {
		            var triggeringItem = getItem(getTriggeringItemStr(input));
		            var state = input.state;
		            if (isUninitialized(state)) state = triggeringItem.state;

		            var itemSensorTriggeredUI = getItem(triggeringItem.name+"UI");
		            // postUpdate(itemSensorTriggeredUI,formatUITimeStampfromJodaDate(DateTime.now()) + "  " + state)
		           logInfo("this is script and state changed of " + getItem(triggeringItem.name) + ", state " + state)
		        }
});

I figured you would run into this since you are on 2.3.0, there has been a breaking api change some time ago regarding triggers:

In earlier versions of openhab, log:set DEBUG made openhab log my logDebug messages, maybe I have to find out where to set the level for org.eclipse.smarthome.script.
I found the breaking statement in my script, a ReentrantLock that is null (for some unexplained reason). The source can be found at https://github.com/cvdenzen/etc_openhab2.
Am I giving up too soon? I have spent many hours (in the last 3 years or so) trying to understand Xtend. And I have never had the feeling that I understood why it didn’t work and why a change made it work (yes, I have had working rules!).
Before moving to Java, I will give jsr223/Javascript a try. First steps are taken, and I hope to get it working (with some help…).

In Karaf console enter log:set debug org.eclipse.smarthome.script

Yes you are :wink: Xtend is still a fairly restricted set of functions compared to Java and Javascript … those for sure will not be easier to understand.
And as Rich and I replied: you will be completely on your own. With Xtend, while it’s got its strangenesses, there’s still people on the forum to help with.

Found the diff, i hope this mobile Screenshot helps

Just use lewie’s original version of this file and you should be good to go with 2.3.0

Thanks, I will take a look at it tomorrow. If by any chance you have a diff command for this (I have cloned the repo and I am using IntellIJ) that would be helpful.

I have cloned Lewie’s repo, checked out his branch upToOH2.3, but no rule seems to work.

Any error messages? Did you install the experimental rule engine?