Okay,to display data in your UI it will always need to end up in an Item. So that decision is made for you.
For your simple rule, you probably could just get rid of all the variables and work with Items directly, Remembering that it is Item states you are interested in.
slowly I despair…
I get this log error:
2020-01-30 20:40:01.256 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Min/Max temp’: Could not cast NULL to java.lang.Number; line 23, column 48, length 33
My rule:
//calculate Min/Max value of the GenMQTTThingRoom temperature
//
//
//
// var Number Room1TempTodayMin = 0.0
// var Number Room1TempTodayMax = 0.0
// var DateTime Room1TempTodayMin_Time
// var DateTime Room1TempTodayMax_Time
rule "Min/Max temp"
when
Item GenMQTTThing_Room1_temp changed
then
//calculate max temp
if ( GenMQTTThing_Room1_temp.state as Number > Room1TempTodayMax.state as Number) {
Room1TempTodayMax.postUpdate(GenMQTTThing_Room1_temp.state as Number) //updating the item Room1TempTodayMax
Room1TempTodayMax_Time.postUpdate(new DateTimeType) //updating the item Room1TempTodayMax_Time
logInfo("Calculate temp Max YES!")
} else
{
logInfo("Calculate temp Max NO!")
}
end
the items:
Number Room1TempTodayMin "Room1TempTodayMin [%.1f °C]" <heating>
Number Room1TempTodayMax "Room1TempTodayMax [%.1f °C]" <heating>
DateTime Room1TempTodayMin_Time "Room1TempTodayMin_Time [%1$tH:%1$tM]" <heating>
DateTime Room1TempTodayMax_Time "Room1TempTodayMax_Time [%1$tH:%1$tM]" <heating>
How can I initalize the item: Room1TempTodayMin, Room1TempTodayMax?
rule "Startup"
when
System started
then
if (Room1TempTodayMax.state == NULL) {
Room1TempTodayMax.postUpdate(0)
}
end
That should work.
Or you could do it in your main rule,the first time you call it. Test for NULL state before using, and just go ahead and do the update without further comparisons.
Later, perhaps you’ll want to make another rule to reset your daily min/max at midnight.