OpenHAB Bug: rule errors

After restarting OpenHAB I get some error messages:

2018-01-04 21:46:14.007 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Strom an bei Schwimmbad Temperatur': The name 'Activate_Pool' cannot be resolved to an item or type; line 7, column 7, length 13
2018-01-04 21:46:15.670 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Strom an bei Schwimmbad Temperatur': The name 'Activate_Pool' cannot be resolved to an item or type; line 7, column 7, length 13
2018-01-04 21:46:15.682 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Strom an bei Schwimmbad Temperatur': The name 'Activate_Pool' cannot be resolved to an item or type; line 7, column 7, length 13
2018-01-04 21:46:28.018 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Strom an bei Schwimmbad Temperatur': The name 'ON' cannot be resolved to an item or type; line 7, column 30, length 2

But I get these only if I restart OpenHAB. When I open and save the rule file, OpenHAB loads it without problems.

Here is the rule:

import org.joda.time.LocalTime

rule "Strom an bei Schwimmbad Temperatur"
when
    Item Temp_Pool received update
then
  if (Activate_Pool.state == ON) {
    val LocalTime morning = new LocalTime(10, 00)  // 10:30 every day
    val LocalTime evening = new LocalTime(17, 30)  // 17:30 every day
    if (now.toLocalTime().isAfter(morning) && now.toLocalTime().isBefore(evening)) {
      // Temperatur mit Punkt statt Komma angeben
      if (Temp_Pool.state < 25) {
        if ( Devolo_Switch.state == OFF ) {
          sendCommand(Devolo_Switch, ON)
          logInfo("schwimmbad-temp.rules","Temperatur unter 25 Grad --> Devolo_Switch - ON")
        }
      } else {
        if ( Devolo_Switch.state == ON ) {
          sendCommand(Devolo_Switch, OFF)
          logInfo("schwimmbad-temp.rules","Temperatur ueber 25 Grad --> Devolo_Switch - OFF")
        }
      }
    } else {
      if ( Devolo_Switch.state == ON ) {
        sendCommand(Devolo_Switch, OFF)
        logInfo("schwimmbad-temp.rules","Nicht in Zeit Bereich")
      }
    }
  }
end

Item:

Switch  Activate_Pool                "Pool-Schaltung aktiv"

Iā€™m using the stable version of OpenHAB 2.2.
Why is this happening?

All I can think of is that your rule is running before all your items files have loaded.

This startet happening with the OpenHAB 2.2 release. So in my opinion this is a bug in OpenHAB

More likely is this has always been doing this. It was in 2.2 that the error is now properly reported. Before, the error was not reported in a way that was human understandable.

And given that it is a timing issue, assuming my interpretation is correct, before you were lucky not to encounter the issue just from the luck of the timing. There is already an issue open to address the problem where rules load and run before items and persistence is done loading, which has been a problem since 2.0.

1 Like

Seems I run into similar issues.

I see several error messages when restarting. They are all like

The name ā€˜blablaā€™ cannot be resolved to an item or type;

The errors are different on each restart. Sometimes the are all about one rules file, or mutltiple different rule files.

But its not limited to items that are not yet properly loaded !

It also complains about global constants like ON

if(GwAlarmSoundActive.state ==ON){

gives

Rule ā€˜GwAlarmSoundRuleā€™: The name ā€˜ONā€™ cannot be resolved to an item or type;

It also affects constants that are defined just a few lines before the error line.

Even logDebug() is sometimes flagged as an error

The name ā€˜logDebugā€™ cannot be resolved to an item or type;

As said, the errors reported change on every reboot. Triggering the reload of files at runtime by touching them works OK.

I first noticed this behaviour after I flashed the RPi SD card with the latest openhabian containing oh2.2. I have never seen this when running OH 2.1.

How long have you been running on that SD card? Weird behavior like that often points to a failing SD card.

Iā€™m aware of the SD wear problem, but this is a relatively new 32GB Samsung Evo plus card. First used around Xmas the card has seen maybe 2 weeks worth of continous use in the RPi without any load on it and the card was never used for anthing but the RPi.
Because of the amazing speed of this SD card I am also pretty sure its an original Samsung and not a fake copy.

I doubt this is a SD wear problem, but just to be sure I will prepare a USB stick later today and try again.

Iā€˜m running OpenHAB in a virtual machine on a normal hard disk and I have exactly the some problems.

I tried a few different setups:
3 different SD cards
USB Stick
USB HDD

All of these are fresh openhabian based setups. The results are mixed and I have no clue why. Sometimes I see errors, sometimes not.

This is maybe the most puzzling error:

The name ā€˜ONā€™ cannot be resolved to an item or type

How can ON be unknown??

After a restart the OH service the errors are either gone, or sometimes replaced by different errors.

Because the other part of the assigment has failed, i.e. the Item didnā€™t resolve. So the interpreter is still looking for an Item and ON doesnā€™t fit the bill.

If the item was unresolveable I would guess the system would give something like
ā€œThe name item.state cannot be resolved to an item or typeā€

But I also had statements like logDebug() and simple variable / constant assignments fail:

val HSBType YELLOW= new HSBType(ā€œ29,100,100ā€)

Rhe errors are most often gone after restarting OH, without changing any file. So this looks like some sort of race condition.