Hello,
I had following script error when running a Timer created in a rule that handles gate opening:
2018-09-25 16:42:35.808 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Commande mCR_portail': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.ScriptExecution.createTimer(org.joda.time.base.AbstractInstant,org.eclipse.xtext.xbase.lib.Procedures$Procedure0) on instance: null
Other topics mention same issue when parameter is wrong type. This is not my case (see code below) and the rule worked properly for several weeks (triggered at least 4 times / day).
Any idea of what could cause the null error? Is it possible that global constants get reset due to other errors with the scripting engine (they were several errors ? I moved them inside the rule block to ensure they get set everytime the rule is triggered but I would like to understand the root cause of the error.
import org.joda.time.DateTime
var Timer portail_task = null
val int portail_opensecs = 26
val int portail_closesecs = 25
val int portail_pietonsecs = 6
rule "Commande mCR_portail"
when
Item DW_mCR_portail received command
then
var new_mode = null
val DateTime now_date = new DateTime()
var DateTime portail_move_start = now_date
var DateTime portail_move_end = now_date.plusMillis(portail_opensecs * 1000 + 500)
portail_task?.cancel()
portail_task = null
switch(DW_mCR_portail.state.toString + ">" + new_mode){
case '0>30':{//CLOSED > PIETON
AC_mCR_portail.sendCommand(ON)
portail_move_start = now_date
portail_move_end = now_date.plusMillis(portail_pietonsecs * 1000 + 500)
DW_mCR_portail.postUpdate(10)//OPENING
portail_task = createTimer(portail_move_end) [|
AC_mCR_portail.sendCommand(ON)
DW_mCR_portail.postUpdate(30) //PIETON
]
}
}
The rule uses a timer to determine the state of the gate because it does not have position sensors. For example, when “OPEN” command is received, the state is set immediately to “OPENING” and a Timer is created to change the state to “OPEN” when opening of the gate it completed after portail_pietonsecs seconds. (I removed all other case {} block to make code lighter).