[SOLVED] Rules, Joys of An error occurred during the script execution

Hi, I bet my error is simple, but the errors could be possibly more helpful, maybe ?

2020-02-29 09:08:03.864 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘KWLoad Logging rules’: An error occurred during the script execution: index=1, size=1

rule “KWLoad Logging rules”

when
Item InstPWR changed or
Item KWloadSetpoint changed

then
//logInfo(“system load.rules”, "cpu load changed " + systeminfo_computer_u2_cpu_load.state.toString )

// if valid ( Not NULL)
// if (KWloadSetpoint.state != NULL) {
// true null/undef check
//if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return
logInfo("Power Usage Trig not NULL ")

if ((InstPWR.state as DecimalType) > (KWloadSetpoint.state as DecimalType)) {

// we have hit a set point for presence ?
postUpdate(PowerUseageTrig,ON)
// toggle ON/OFF for 5m presence

logInfo("Power Usage Trig ON " + PowerUseageTrig.state.toString )

//main log
if (KWModeSW.state ==1 || KWModeSW.state ==3) { postUpdate(MainLog, "W Useage : " + InstPWR.state.toString) } //$Log
if (KWModeSW.state ==2 || KWModeSW.state ==3) { SendTelegram.postUpdate("W Useage : " + InstPWR.state.toString) } //VTelegram
}

else
// needs small delay
postUpdate(PowerUseageTrig,OFF)

// }

end

It’s quite difficult to interpret the rule without code fencing, without indents etc.

rule “KWLoad Logging rules”
when
   Item InstPWR changed or
   Item KWloadSetpoint changed
then
   //logInfo(“system load.rules”, "cpu load changed " + systeminfo_computer_u2_cpu_load.state.toString )

// if valid ( Not NULL)
// if (KWloadSetpoint.state != NULL) {
// true null/undef check
//if (triggeringItem.state == NULL || triggeringItem.state == UNDEF) return
   logInfo("Power Usage Trig not NULL ")

   if ((InstPWR.state as DecimalType) > (KWloadSetpoint.state as DecimalType)) {

// we have hit a set point for presence ?
       postUpdate(PowerUseageTrig,ON)
// toggle ON/OFF for 5m presence

       logInfo("Power Usage Trig ON " + PowerUseageTrig.state.toString )

//main log
      if (KWModeSW.state ==1 || KWModeSW.state ==3) { 
         postUpdate(MainLog, "W Useage : " + InstPWR.state.toString) } //$Log
      if (KWModeSW.state ==2 || KWModeSW.state ==3) { 
         SendTelegram.postUpdate("W Useage : " + InstPWR.state.toString) } //VTelegram
   }
   else
// needs small delay
      postUpdate(PowerUseageTrig,OFF)

// }
end

Most of your diagnostic aids are commented out.
If my interpretation of your rule is correct and this isn’t commented out -
logInfo("Power Usage Trig not NULL ")
it’s faulty syntax. logInfo() requires at least two parameters.

VSCode with openHAB extension is a useful tool for catching basic syntax errors.

I find this web ui awkward/not helpful to get the indent to work, to appears to indent the first line and thats it.

Also unable to reply inline to individual comments just at the end ?

I was commenting out script that were not ready to be used yet, and proposed new additions which are no use with unhelpful errors of index 1, size 1 ,how would that relate to line 14 ?

I assumed it was stalling on the use of !=NULL or a variation of this test ie NOT NULL or null

VScode is installed with openHAB extension , yet says nothing

Thanks for you input on this

So, you’ve fixed it?

It depends what forum tool you use.

If you highlight part of a post, a “quote” popup appears. Is that what you mean?

I don’t understand your question.
Yes, it’s an unhelpful error message.

Validation is done at openHAB itself. If you use VSCode without a “live link” to your openHAB, you do not get full validation.
When that is working, VSCode will highlight an attempt to use logInfo() with only one parameter.

1 Like

trying to code block indent