2020-11-27 10:47:57.039 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Funkcja przepisująca wartość ITEM do zmiennej - TempWlPompyWBasenie': context

On OH 2.5 i have such issue…

Fragment of rule file:

var Number TempWlPompyWBasenie              // Temperatura wlaczenia pompy w basenie (ładowana w funkcjach z ITEM)
//...and few lines bellow that...
rule "Funkcja przepisująca wartość ITEM do zmiennej - TempWlPompyWBasenie"
  when
    System started or
	  Item TempWlPompyWBasenieITM changed
  then
    logInfo("rules.IB","REGRUN: Funkcja przepisująca wartość ITEM do zmiennej - TempWlPompyWBasenie: " + TempWlPompyWBasenieITM.state)
    TempWlPompyWBasenie = (TempWlPompyWBasenieITM.state as Number).intValue
end

Somehow that rule (sometimes when system starts) generates ERROR:

2020-11-27 10:47:57.039 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule ‘Funkcja przepisująca wartość ITEM do zmiennej - TempWlPompyWBasenie’: context

I have to add, that in events.log I can see that item “TempWlPompyWBasenieITM” value was loaded from persistance about 1 min earlier.

Any clue why?

First of all I would determine whether the error is caused by the logInfo line or the assignment line. Comment out one of them and see if the issue still occurs.

Most likely there is a mismatch of types in your data. Although you write that the value was loaded beforehand, is the value of the correct type? One that can be converted to int?

I think @stefan.oh might be on the right track…

var Number TempWlPompyWBasenie
TempWlPompyWBasenie = (TempWlPompyWBasenieITM.state as Number).intValue

An int is not a Number type. Try declaring your variable as an int instead.

No, Number is all type of numbers, may it be an int value or float, double, with or without units… and the Error is not about a wrong type but about the context, which is a weird error…
I’m not sure if it’s allowed to declare (but not set) a var.
Did you write the first line (var definition) at top of file? Global vars must be defined before any rule.

Another thing: you are using TempWlPompyWBasenieITM.state in logInfo, but it has to be a string here.

// global vars on top of file!
var Number TempWlPompyWBasenie = null              // Temperatura wlaczenia pompy w basenie (ładowana w funkcjach z ITEM)
//...and few lines bellow that...
rule "Funkcja przepisująca wartość ITEM do zmiennej - TempWlPompyWBasenie"
when
    System started or
    Item TempWlPompyWBasenieITM changed
then
    logInfo("IB","REGRUN: Funkcja przepisująca wartość ITEM do zmiennej - TempWlPompyWBasenie: " + TempWlPompyWBasenieITM.state.toString)
// this line should also work fine:
//    logInfo("IB","REGRUN: Funkcja przepisująca wartość ITEM do zmiennej - TempWlPompyWBasenie: {}",TempWlPompyWBasenieITM.state)
    TempWlPompyWBasenie = (TempWlPompyWBasenieITM.state as Number).intValue
end

I have several rule files where I define vars at the top of the file and in one of them the vars are NOT set to specific values. I did not encounter any obvious issues due to that, the (single) rule in that file is executed every work day without issues.
I was more thinking about a value of NULL or “not initialized” writing my answer. So I’m interested in what the logfile shows as output for the loginfo line. I usually tend to add something like '+ “#” ’ to really see leading and/or trailing whitespace content that might lead to unexpected behaviour. Might not be the case here, but I suspect that re-using values from persistence may play a role in the issue here. Without knowing what the value really is, everything will be speculative I’m afraid.