[Partly solved] Rules are not triggered as expected

I installed yesterdays nightly (#413) manually using a script (not apt -get!)
When starting the OpenHAB service initially my rule which is based on an Item state change(network item) is triggered as expected. The rule which is based on a cron-statement and System started is NOT performed after the start (IMHO which it should be), however the cron-events of the rule are performed.

If I do stop and then restart the service (either by using those commands or by rebooting) both type of events are not triggered ( Item state change AND System started).

A Trigger with an AND is not possible, because both events must occur at the same femto second. In the when clause only a or is usable.


To elaborate on @Dibbler42’s answer, a rule is triggered be an event. Any further logic you need to do needs to be performed within the rule in an if statement. An an event is discreet and has no duration. For how long after the System started should the Item state changed be considered enough to trigger the rule?

In this case the event is “System started”. In the rule you would have:

if(item.state == "something") {
    // do stuff

Because no two events will ever happen at the exact same time, if you truly need to do something in case of both of these events, you need to do some fancy book keeping.

  • create a timer for both Items
  • create a rule for each trigger on the events
  • check whether either of the timers is active in the rule and if it is you know that the two events occurred close together in time.

val Timer startedTimer = null
val Timer itemTimer = null

rule "System started, check for Item changed"
    System started
    if(itemTimer != null) {
        // the Item changed state close to the system starting logic goes here
    else {
        startedTimer = createTimer(now.plusSeconds(1), [|    startedTimer = null ])

rule "MyItem changed state"
    Item MyItem changed
    if(startedTimer != null){
        // MyItem changed state close to System started logic goes here
    else {
        itemTimer = createTimer(now.plusSeconds(1), [| itemTimer = null])

However, WHY do you want this? There might be a more appropriate way to achieve what you are after.

1 Like

Stupid me, I used the “and” in the sentence, however the trigger is naturally set up with “or”. Both rules where working before this update.
My question is, why are those rules not working anymore as expected?

Thanks for the help!

It is always easiest for others to reproduce your problem if you can show it on the demo setup. The demo comes with a demo.rules file, which contains cron as well as startup rules. Imho they are all working. So what needs to be changed about them to make your problem appear?

I made a clean install of the todays nigthly (#417 / clean as in deleting the whole directory that contained openhab2) and started with the demo setup. When adding the following rule to the running OpenHAB:

import org.openhab.core.library.types.*
val String Tankstelle1_ID="xxxxx"
val String API_Key="xxxx"
var String Status
var String TankstellenMarke
var String TankstellenStrasse
var String TankstellenOrt
rule "Tankstellendaten"
Time cron “50 3 0 * * ?” or System started
logInfo (“Tankstellendaten”, “Start”)
var String URL= “https://creativecommons.tankerkoenig.de/json/detail.php?id=” + Tankstelle1_ID + “&apikey=” + API_Key
//logInfo (“Tankstellendaten”, “URL = {}”, URL)
var String json = sendHttpGetRequest(URL)
//logInfo(“Tankstellendaten”,“JSON-String = {}”, json)
if (json!=null) {
var String OK = transform(“JSONPATH”, “$.ok”, json)
//logInfo(“Tankstellendaten”, “OK = {}”, OK)
if (OK==“true”) {
TankstellenMarke = transform(“JSONPATH”, “$.station.brand”, json)
TankstellenStrasse = transform(“JSONPATH”, “$.station.street”, json)
TankstellenOrt = transform(“JSONPATH”, “$.station.place”, json)
Name_1.postUpdate(TankstellenMarke + " " +TankstellenStrasse + " " + TankstellenOrt)
else {
var String HttpError = transform(“JSONPATH”, “$.message”, json)
logInfo(“Tankstellendaten”, “HttpError = {}”, HttpError)
else {
logInfo(“Tankstellendaten”, “Empty Return from HTTPRequest”)

The rule was triggered immidiatly in this demo setup (verified by log-entry and output to Item Name_1).
After that I changed the setup to standard using this addons.cfg file:

package = standard
binding = sonos, network, intertechno, exec, http
ui = basic, classic, paper
persistence = rrd4j, mysql
transformation = map, jsonpath, exec, regex
misc = myopenhab

After starting OpenHAB in this setup the above rule was NOT performed immidiatly, only when changing the cron-statement to the actual time it was performed.

Didn’t have time to do the check on for the Item-Changed rule. That has to wait until tomorrow.

Checked for the Rule which is triggered on using “Item Juergen_WLAN changed to ON”. Used the Demo setup, with all of my Items, Sitmap and rules removed initially. When adding the above triggered rule, it is triggered. However, if changing to the standard setup it is NOT triggered.

Using a “log:set DEBUG org.eclipse.smarthome.model” and saving a change to the rule with “cron xxx or System started” I get those log-entries:

19:55:25.946 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'price.rules’
19:55:26.209 [DEBUG] [e.internal.engine.RuleTriggerManager] - Removed scheduled cron job 'price.rules#Tankstellendaten#50 3 0 * * ?'
19:55:26.223 [DEBUG] [e.internal.engine.RuleTriggerManager] - Scheduled rule Tankstellendaten with cron expression 50 3 0 * * ?
19:55:31.225 [DEBUG] [ntime.internal.engine.RuleEngineImpl] - Executing startup rule ‘Tankstellendaten’

The last entry tells it is executing the startup rule, however the rule is not performed (expected LogInfo isn’t logged).

…and now I’m completly lost!
I left the system untouched since the test yesterday evening and looked at the log this morning.
Now I see the “Item changed” triggered rule being done. Starting with the Error " script interpreter couldn’t be obtain", I thought that one was resolved.

I’m still having this problem!:rage:
I hate those problems that seem to come and go. I’ve been writing enough code to know that is a stupid description, but that’s what it looks like to me.

All I can figure out is that only those rules do get their starting event when the event is scheduled by a cron-statement.
It doesn’t matter if the cron is paired with another statement (paired by “or”!) or it is alone, the cron works.
All others like “System started” or any “Item Changed” do not. The one raised by “System started” reports itself “started” when using:

“log:set DEBUG org.eclipse.smarthome.model”

However the code is NOT performed!
Actualy I’m testing it with a “Test-Rule” like this:

rule "Tester"
Time cron “0 2,7,12,17,22,27,32,37,42,47,52,57 * * * ?” or Item TestSomething changed to ON
logInfo(“Tester”,“TestSomesting = {}”, TestSomething)

The rule does run every 5 minutes as planned, however a try to run it by switching the swich “TestSomething” isn’t working! The log looks like :slight_smile:

21:42:00.011 [DEBUG] [ntime.internal.engine.ExecuteRuleJob] - Executing scheduled rule 'Tester’
21:42:00.028 [INFO ] [clipse.smarthome.model.script.Tester] - TestSomesting = TestSomething (Type=SwitchItem, State=OFF, Label=Test, Category=null, Groups=[EG_Wohnzimmer])

If anybody who is working on a nigthly #413 or later has the rules working correctly, could (s)he post the bundle:list output. Maybe I still have something stupid in my setup although I did a complete reinstall.

Found the problem ( at least I think so).
I had some entries of an apt -get installation remains on the system. After removing that the Item changed rules are again.
The remaining problem is the rule which should react on system started. It had been that such a rule triggered whenever the rule-file got an update. This isn’t working!
Since I get the above mentioned log-entry that the rules supposed to be started, I believe that this is not an expected behavior.
The rule itself has no errors, the Cron trigger in the same rule works!
The problem came back after a day??
I’ll make a complete reinstall of the OS after my vacation. Will report back!

I today fixed a major bug that caused rules to not execute correctly with a kind of random behavior. I would hope that many of those problem reports are solved with it - the fix is part of the latest build #469 already. So please be so kind and test this!

For me #464 AND the correct usage of Linked mode together with an .items file solved the problems.
Nevertheless I will test it as soon as I’m back home at the end of the week.
Thanks for the effort.

Installed #469. No problems observed regarding my rules.