OpenHAB Bug: rule errors

rules
Tags: #<Tag:0x00007f6ce5ffa3f8>

(Maximilian) #1

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?


(Rich Koshak) #2

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


(Maximilian) #3

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


(Rich Koshak) #4

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.


(rb) #5

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.


(Rich Koshak) #6

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


(rb) #7

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.


(Maximilian) #8

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