2015-10-20 17:45:44.204 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Increment Generator Runtimes
java.lang.RuntimeException: The name 'java' cannot be resolved to an item or type.
And this is the full script:
var org.joda.time.DateTime whenStarted = null
rule "Generator started"
when
Item Generator received command ON
then
whenStarted = now
end
rule "Generator stopped"
when
Item Generator received command OFF
then
if(whenStarted != null) {
// do the same as the if(Generator.state == ON && whenStarted != null) in the increment rule
}
whenStarted = null
end
rule "Increment Generator Runtimes"
when
Time cron "* */1 * * * ?"
then
if(Generator.state == ON && whenStarted != null){
logInfo("GenUptime", "Getting now")
val long nowMsec = now.millis
logInfo("GenUptime", "Getting whenStarted")
val long wsMsec = whenStarted.millis
logInfo("GenUptime", "Resetting whenStarted")
whenStarted = now
logInfo("GenUptime", "Calculating time difference")
val long timeSinceLastUpdate = nowMsec - wsMsec
logInfo("GenUptime", "Getting total Uptime in msec")
val long oldVal = if(GeneratorRuntimeMSec.state == Undefined || GeneratorRuntimeMSec.state == Uninitialized) 0 else (GeneratorRuntimeMSec.state as Number).longValue
logInfo("GenUpTime", "Adding current time to total: timeSinceLastUpdate = " + timeSinceLastUpdate + " oldVal = " + oldVal)
val long totalMsec = oldVal + timeSinceLastUpdate // calculate total runtime<F2>
logInfo("GenUptime", "Posting totalMsec to Item")
GeneratorRuntimeMSec.postUpdate(totalMsec) // post the full runtime
logInfo("GenUptime", "Calculating hours")
val long hours = java.lang.Math.round(totalMsec/1000/60/60)
logInfo("GenUptime", "Posting hours")
GeneratorRuntimeHours.postUpdate(hours)
}
else if(Generator.state == ON && whenStarted == null){
logInfo("GenUptime", "Generator is ON but Generator started rule never executed")
whenStarted = now
}
else {
logInfo("GenUptime", "Generator is not running")
}
end