Hello All
I have working OH2.5 with mqtt binding and boiler switch that works fine with rules
When I try to move the switch to new fresh install OH3 the same rule is not working with error
The item itself works Ok
Item:
String Boiler_Switch_Dummy
DateTime strBoiler_Start_Time
DateTime strBoiler_End_Time
Switch swBoiler "Boiler" { channel="mqtt:topic:swBoiler:power", channel="mqtt:topic:swBoiler:state_power"}
String strBoilerP { channel="mqtt:topic:swBoiler:pulseTime1" }
Rule:
var Timer boilerOff5Minute = null
rule "Trun on Boiler with timer"
when
Item Boiler_Switch_Dummy received command
then
strBoiler_Start_Time.postUpdate (new DateTimeType())
Thread::sleep(3000)
switch (Boiler_Switch_Dummy.state){
case "0":{
//strBoiler_Rule1.sendCommand("ON Power1#state=1 DO RuleTimer1 10 ENDON ON Rules#Timer=1 do Power1 off ENDON")
strBoilerP.sendCommand(1900)
strBoiler_End_Time.postUpdate((new DateTimeType(new DateTime((strBoiler_Start_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli).plusMinutes(30).toString)))
boilerOff5Minute = createTimer(now.plusMinutes(25), [|
sendBroadcastNotification ("Boiler is OFF in 5 minute.")
boilerOff5Minute?.cancel
boilerOff5Minute = null
])
}
case "1":{
//strBoiler_Rule1.sendCommand("ON Power1#state=1 DO RuleTimer1 20 ENDON ON Rules#Timer=1 do Power1 off ENDON")
strBoilerP.sendCommand(3700)
strBoiler_End_Time.postUpdate((new DateTimeType(new DateTime((strBoiler_Start_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli).plusMinutes(60).toString)))
boilerOff5Minute = createTimer(now.plusMinutes(55), [|
sendBroadcastNotification ("Boiler is OFF in 5 minute.")
boilerOff5Minute?.cancel
boilerOff5Minute = null
])
}
case "2":{
//strBoiler_Rule1.sendCommand("ON Power1#state=1 DO RuleTimer1 30 ENDON ON Rules#Timer=1 do Power1 off ENDON")
strBoilerP.sendCommand(5500)
strBoiler_End_Time.postUpdate((new DateTimeType(new DateTime((strBoiler_Start_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli).plusMinutes(90).toString)))
boilerOff5Minute = createTimer(now.plusMinutes(85), [|
sendBroadcastNotification ("Boiler is OFF in 5 minute.")
boilerOff5Minute?.cancel
boilerOff5Minute = null
])
}
}
Thread::sleep(3000)
swBoiler.sendCommand("ON")
Boiler_Switch_Dummy.postUpdate(-1)
//sendBroadcastNotification ("Boiler is ON from " + strBoiler_Start_Time.state.format("%1$tH:%1$tM") + " to " + strBoiler_End_Time.state.format("%1$tH:%1$tM"))
end
rule "Boiler changed"
when
Item swBoiler changed
then
logInfo("notifications", "swBoiler changed to " + swBoiler.state + " " + boilerOff5Minute)
if(swBoiler.state == OFF){
sendBroadcastNotification ("Boiler is OFF")
boilerOff5Minute?.cancel
boilerOff5Minute = null
}
else {
if(boilerOff5Minute === null){
strBoiler_Start_Time.postUpdate (new DateTimeType())
Thread::sleep(3000)
strBoiler_End_Time.postUpdate((new DateTimeType(new DateTime((strBoiler_Start_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli).plusMinutes(30).toString)))
boilerOff5Minute = createTimer(now.plusMinutes(25), [|
sendBroadcastNotification ("Boiler is OFF in 5 minute.")
boilerOff5Minute?.cancel
boilerOff5Minute = null
])
sendBroadcastNotification ("Boiler button is ON from " + strBoiler_Start_Time.state.format("%1$tH:%1$tM") + " to " + strBoiler_End_Time.state.format("%1$tH:%1$tM"))
}
}
end
and the error is:
2021-03-29 23:41:10.809 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'boiler-1' failed: An error occurred during the script execution: Cannot assign a value in null context. in boiler
I’m using switch with 3 option in sitemap
Switch item=Boiler_Switch_Dummy label="בוילר" mappings=[0=" 30 Min ", 1=" 60 Min ", 2=" 90 Min "]
Where that null came from?
TIA