An error occurred during the script execution: null

I am seeing the following errors occasionally in the log file. The rule is one that came recommended with the EcoBee binding to track changes in occupancy.

Anyone share some insight as to what might be going on?

2017-12-10 18:35:10.000 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'D_LastMotionOFF': An error occurred during the script execution: null
2017-12-10 18:17:06.540 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'U_LastMotionOFF': An error occurred during the script execution: null

RULE:

var D_DateTime
var U_DateTime

//Downstairs
rule D_LastMotionON
when
    Item D_Hvac_Occu changed to ON
then
    postUpdate(D_Hvac_LastOccuTime, new DateTimeType())
end

rule D_LastMotionOFF
when
    Item D_Hvac_Occu changed to OFF
then
    switch D_Hvac_LastOccuTime.state {
      DateTimeType: {
        var D_DateTime halfHourAgo = now.minusMinutes(30)
        var D_DateTime lastKnownMotion = new D_DateTime((D_Hvac_LastOccuTime.state as DateTimeType).calendar.timeInMillis)
        if (halfHourAgo.isAfter(lastKnownMotion)) {
          D_Hvac_LastOccuTime.postUpdate(new DateTimeType(halfHourAgo.toString))
        }
      }
    }
end

//Upstairs
rule U_LastMotionON
when
    Item U_Hvac_Occu changed to ON
then
    postUpdate(U_Hvac_LastOccuTime, new DateTimeType())
end


rule U_LastMotionOFF
when
    Item U_Hvac_Occu changed to OFF
then
    switch U_Hvac_LastOccuTime.state {
      DateTimeType: {
        var U_DateTime halfHourAgo = now.minusMinutes(30)
        var U_DateTime lastKnownMotion = new U_DateTime((U_Hvac_LastOccuTime.state as DateTimeType).calendar.timeInMillis)
        if (halfHourAgo.isAfter(lastKnownMotion)) {
          U_Hvac_LastOccuTime.postUpdate(new DateTimeType(halfHourAgo.toString))
        }
      }
    }
end

Thanks,

Well, the rule is incorrect :wink:

There is a command switch, but as far as I know, this is to decide between two or more options, given by another command case

So the rule should be more like

rule D_LastMotionOFF
when
    Item D_Hvac_Occu changed to OFF
then
    var DateTime halfHourAgo = now.minusMinutes(30)
    var DateTime lastKnownMotion = new DateTime((D_Hvac_LastOccuTime.state as DateTimeType).calendar.timeInMillis)
    if (halfHourAgo.isAfter(lastKnownMotion)) {
        D_Hvac_LastOccuTime.postUpdate(new DateTimeType(halfHourAgo.toString))
    }
end

@Udo_Hartmann

Thank you for the information…

Quick question…is the syntax issue something that VS Code should have caught and displayed as an error?

Thanks,

Squid

As switch {} is a key word, I doubt that VSCode will complain about that part.

Do you use the current version of VSCode + openHAB plugin and also the current Snapshot of openHAB2.2 ?

VSCode has to be setup to use LSP from openHAB2.

I am using the latest version of vs code and the OH plugin…I may have stepped back a version or two on the snapshot as I’ve been encountering issues with the HUE Emulation plugin and haven’t found a fix as of yet.

@Udo_Hartmann

I implemented the change you suggested above and now see the following in my openhab.log

Rule 'D_LastMotionOFF': An error occurred during the script execution: The name '<XFeatureCallImplCustom>.isAfter(<XFeatureCallImplCustom>)' cannot be resolved to an item or type.

Suggestions?

1 Like

When you write

var D_DateTime halfHourAgo

You tell OpenHAB to create a variable of type D_DateTime, which is not a valid type (someone correct me if I’m wrong), and since the type does not exist, it doesn’t have the isAfter() method.

Try to use

var DateTime ...

instead

Thank you for the information… @pacive

The reason I appended a D_to D_DateTime is the fact that I have two similar rules on the same page…one for the DOWNSTAIRS thermostat which is D_DateTime and one for the UPSTAIR thermostat U_DateTime.

I was concerned about using the same variable for both. If I need to remove the prefix, should I break the rules into separate files?

Sorry for that typo… have corrected this one above.

The point is:

var DateTime D_halfHourAgo
^      ^       ^ named D_halfHourAgo
|     of Type DateTime
define a variable 

This is the meaning of the code line
Of course, if defining a var within a rule, the name will only be used in this rule, so, you don’t need to differ these var names.