Rule issue: cannot be resolved to an item or type

Hi folks,

not sure I can understand what is happening.

System restarted, I see this error in my logs:

018-08-23 15:55:17.933 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'uvindex maxtime visibility': The name 'Openuv_UVIndexMaxTime_Status' cannot be resolved to an item or type; line 23, column 17, length 28

but the item exists.

Switch Openuv_UVIndexMaxTime_Status

Maybe a mistake in my rule?

rule "uvindex maxtime visibility"
when
    Item Openuv_UVIndex changed
then
    val openuvmaxtime = new DateTime(Openuv_UVIndexMaxTime.state.toString)
    if (now.isAfter(openuvmaxtime)) {
    sendCommand(Openuv_UVIndexMaxTime_Status, OFF)
    }
    else {
        sendCommand(Openuv_UVIndexMaxTime_Status, ON)
    }
end

the idea of the rule is to check the current UV Index, and if this changes and we are in a period of time after the peak of UV for the day, I set the switch “Openuv_UVIndexMaxTime_Status” to OFF.

Any clue?

Thanks
Andrea

It does that sometimes.

Sometimes the rules end uploading before items are fully loaded.

It used to be in OH1 you could specify which to load first and how long to pause on start up to prevent issues like this. I don’t see it in OH2. But OH2 has been pretty good about this. I rarely ever see this error.

Any suggestion how to trigger rules after all items are fully loaded?

I’m on OH2

The sendCommand action takes strings as arguments.
Use the method instead:

Openuv_UVIndexMaxTime_Status.sendCommand(OFF)

same error in my logs :frowning:

There are all sorts of very complex work arounds involving Timers and Rules that copy the .rules files after a certain number of seconds/minutes after the system boots and the like. In my opinion, it is easier to ignore the errors during boot.

There has been an issue open on this since OH 2.0. It’s a well known problem that is not trivial to fix apparently.

It should rarely be an actual problem in practice, mainly if it occurs during a System started Rule therefore preventing something that should occur at startup from occurring. In that case, you can put that part into a Timer and schedule it to take place when you know it’s safe.

1 Like

Understood … thank you Rich, much appreciated

Andrea

Rich,

I’ve tried this solution:

rule "Set Danfoss_Hallway_Radiator_BatteryAlarm Flag"
when
    Item Danfoss_Hallway_Radiator_BatteryLevel changed or
    Item Astro_Sun_Season_Name received update
then
    Thread::sleep(25000)
    if ((Danfoss_Hallway_Radiator_BatteryLevel.state == NULL) || (Astro_Sun_Season_Name.state == NULL)) {
        return;
    }
    if(Danfoss_Hallway_Radiator_BatteryLevel.state <= 10 && Astro_Sun_Season_Name.state.toString.contains("AUTUMN") || Danfoss_Hallway_Radiator_BatteryLevel.state <= 10 && Astro_Sun_Season_Name.state.toString.contains("WINTER") || Danfoss_Hallway_Radiator_BatteryLevel.state <= 10 && Astro_Sun_Season_Name.state.toString.contains("SPRING")) Danfoss_Hallway_Radiator_BatteryAlarm.sendCommand(ON)
    else Danfoss_Hallway_Radiator_BatteryAlarm.sendCommand(OFF)
end

here the error:

2018-11-05 11:49:17.030 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Set Danfoss_Hallway_Radiator_BatteryAlarm Flag': The name 'Thread' cannot be resolved to an item or type; line 8, column 5, length 6

AHAHAHA … not sure how to fix it :slight_smile:
I will ignore if no other option is available :slight_smile:
thanks

Andrea

Why would you want to sleep for 25 seconds before the rule execute?

Because the issue above. I’m trying to reduce the possibility to have items not yet populated before triggering the rule.

Even with persistence, I have the issue above

I have some of these errors when restarting openHAB. I ignore them
The persistence will do it’s job eventually or the bindings…
The after a little while openHAB settles down.

Doing a Thread::sleep for 25 seconds is a very bad idea in the first place:

better to use a createTimer(now.plusSeconds(25), [| ] ?

Yes. That is what I meant above when I said put that part into a Timer and schedule it to take place when you know it’s safe.

But as you are seeing, sometimes you can’t guarantee that core Objects exist when the Rules start running like Thread and Timer. So there will be times when even that won’t work.

In fact, it’s very unlikely that openHAB doesn’t recognize the item in a rule file.
Are you sure that the Item is populated? It’s possible that the item file has errors and the Item isn’t created at all.
In question of your rule, it would be easier to use another if() statement:

rule "Set Danfoss_Hallway_Radiator_BatteryAlarm Flag"
when
    Item Danfoss_Hallway_Radiator_BatteryLevel changed or
    Item Astro_Sun_Season_Name changed
then
    if (!(Danfoss_Hallway_Radiator_BatteryLevel.state instanceof Number) || (Astro_Sun_Season_Name.state == NULL)) {
        return;
    }
    if((Danfoss_Hallway_Radiator_BatteryLevel.state as Number)<= 10 && !(Astro_Sun_Season_Name.state.toString.contains("SUMMER") )
        Danfoss_Hallway_Radiator_BatteryAlarm.sendCommand(ON)
    else 
        Danfoss_Hallway_Radiator_BatteryAlarm.sendCommand(OFF)
end

There is no need to trigger on every update. It’s better to check if the battery level is of type Number, as you want to check it it’s less or equal.

I’ve had it report just about everything possible as unknown symbols during OH initial startup. Global variables, constants like NULL, ON, OFF, etc, base Java classes like Thread::sleep as reported above, etc. Every time we restart OH we are rolling the dice. Sometimes it completes with no errors, sometimes it throws the strangest errors that make absolutely no sense. I’ll be very happy when this gets fixed.

2 Likes

I’ve just had the same problem. I had a rule that was triggered by item Something in the when clause, and in its then clause, I wanted to use Something.state, but always got

The name 'Something' cannot be resolved to an item or type

when using the state – even though that very item had triggered the rule!?!

Trying to track down the problem, I inserted a log display first thing after the then

logInfo("rule#1", "Item changed to {}", Something)

The funny thing was: the item was logged, and the error disappeared! It seems like logging the item made it available to the rules engine?!

I think it is more likely that the logging gave the Rule engine enough time to finish loading the Items and make them available to the rules engine. One of the frustrating things with this problem is it all boils down to timing which can often turn the problem into a Heisenbug (i.e. a bug that goes away as soon as you try to change things to find it).

2 Likes

We developers sure do like our puns. :smiley:

I think it is more likely that the logging gave the Rule engine enough time to finish loading the Items and make them available to the rules engine.

Maybe you’re right, but then I still don’t understand how the item can trigger the rule, yet not be available inside it.