Hi all, now that it is getting cold I have the heater setup and the propane turned on this weekend. Just in time. Having moved to OH3 at the new greenhouse I am moving my rules over and have run into an issue. I have several rules that provide data for the heater. Most are not working.
I get the following error:
Script execution of rule with UID 'mainheater-2' failed: An error occurred during the script execution: null in mainheater
I don’t understand what UID ‘mainheater-2’ refers to.
I any case, here is the rule that this is referring to. I think. I have multiple rules around the heater functions so one step at a time.
rule "Main Heater time ascending"
when
Time cron "0 * * * * ?"
then
if( MainHeater.state == ON ) {
var DateTime m = new DateTime(MainHeater.lastUpdate )
var diff = now.millis - m.millis;
MainHeater_On_Asc.postUpdate( diff );
logInfo("Track Ascending Duration", "MainHeater changed last after " + diff )
}
else {
MainHeater_On_Asc.postUpdate( 0 );
}
end
rule "Main Heater On time total"
when
Item MainHeater received command
then
if( receivedCommand==OFF ) {
var DateTime m = new DateTime(MainHeater.lastUpdate )
var diff = now.millis - m.millis;
MainHeater_On_Duration.postUpdate( diff );
logInfo("Track On Duration", "MainHeater on duration was " + diff )
}
else {
logInfo("Track On Duration", "MainHeater is now on " )
}
end
I also have this rule:
var DateTime whenStarted = null
var Timer MainHeater_timer = null
rule "Main Heater Started"
when
Item MainHeater received command ON
then
if (MainHeater_timer === null) { /// Check equivalent to lock
MainHeater_timer = createTimer(now.plusSeconds(45), [ |
if (MainHeater.state == ON) {
whenStarted = now // Start Clock
MainHeater_Failed.postUpdate(OFF)
MainHeater_Cooling.postUpdate(OFF)
createTimer(now.plusSeconds(15), [ |
//sendMail("myemail@gmail.com", "MainHeater", "Main Heater Started, load at " + Buy_Total_Watts.state + " watts")
])
} else {
whenStarted = null
MainHeater_Failed.postUpdate(ON)
MainHeater_Override.postUpdate(OFF)
//sendMail("myemail@gmail.com", "Main Heater", "Main Heater Failed to Start!!")
}
MainHeater_timer = null
])
}
end
rule "Main Heater Stopped"
when
Item MainHeater received command OFF
then
whenStarted = null //Stops clock
MainHeater_Cooling.postUpdate(ON)
createTimer(now.plusSeconds(90), [ |
MainHeater_Cooling.postUpdate(OFF)
])
end
rule "Check Main Heater and Increment Runtimes"
when
Time cron "0 0/1 * * * ?"
then
// Check if MainHeater failed
if (MainHeater_Failed.state == ON) {
//sendMail("myemail@gmail.com", "Main Heater", "Main Heater Failed!!")
}
// Increment Runtimes
if (MainHeater.state == ON && whenStarted !== null) {
val Number nowMSec = now.millis
val Number wsMSec = whenStarted.millis
whenStarted = now
val Number timeSinceLastUpdate = nowMSec - wsMSec
val Number oldVal = if (MainHeater_Runtime_MSec.state == UNDEF || GeneratorRuntimeMSec.state == NULL) 0 else GeneratorRuntimeMSec.state as Number
val Number totalMSec = oldVal + timeSinceLastUpdate // calculate total runtime
MainHeater_Runtime_MSec.postUpdate(totalMSec) // post the full runtime
val Number hours = totalMSec / 3600000 // (1000 / 60 / 60)
MainHeater_Runtime_Hours.postUpdate(hours)
// Calculate runtime for today
val Number todayOldVal = if(Today_MainHeater_Runtime_MSec.state == UNDEF || Today_MainHeater_Runtime_MSec.state == NULL) 0 else (Today_MainHeater_Runtime_MSec.state as Number).longValue
val Number todayTotalMSec = todayOldVal + timeSinceLastUpdate // calculate total runtime
Today_MainHeater_Runtime_MSec.postUpdate(todayTotalMSec) // post the full runtime
val Number todayHours = todayTotalMSec/1000.0/60.0/60.0
Today_MainHeater_Runtime_Hours.postUpdate(todayHours)
}
end
//Timestamp for Main Heater Last Run
rule "Timestamp for Main Heater Last Run"
when
Item MainHeater received command ON // Heater Run
then
MainHeater_timestamp.postUpdate(new DateTimeType()) //defaults to now
logInfo("mainheatertime", "Main Heater Timestamp :"+MainHeater_timestamp.state )
end
rule "Today Main Heater Runtime Reset"
when
Time cron "50 59 23 * * ?"
then
Today_MainHeater_Runtime_MSec.postUpdate(0)
Today_MainHeater_Runtime_Hours.postUpdate(0)
end
I guess I don’t know which rule that error applies to but assuming the mainheater.rule.
This is a rule that @vzorglub helped with. I have the items and persistence setup.
Any help much appreciated!