I receive a strange error from time to time i am struggling to find a reason within my rule.
I have three groups for a bunch of thermostats. gActTemp contains all current temperature readings, gSetTemp contains all target temperatures and a group of unbound Numbers contains the diff (gDiffTemp).
The rule triggers on a update of gActTemp, finds the last changed temperature, chooses the corresponding target & diff items and calculates the difference between current and target temperature again.
All my items are named correctly, and the error is not existing regularly. What is even stranger about it, if i uncomment the three logInfo’s, the error is at least from my mind no longer exisiting.
I hope any of the rule experts may help. Thanks.
This is the rule:
rule "calc diff temp"
when
Item gActTemp received update
then
//Thread::sleep(1000)
// logInfo("heizung", "sleep")
val NumberItem actitem = gActTemp.members.filter[t|t.lastUpdate("mapdb") !== null].sortBy[lastUpdate("mapdb")].last
if (actitem !== null)
{
val NumberItem setitem = gSetTemp.members.filter[i|i.name==String::format("%s_SETTEMP",actitem.name.split("_").get(0))].last
// logInfo("heizung", setitem.name)
val NumberItem diffitem = gDiffTemp.members.filter[i|i.name==String::format("%s_DIFFTEMP",actitem.name.split("_").get(0))].last
// logInfo("heizung", diffitem.name)
if (setitem !== null && diffitem !== null)
{
var Number diff = (actitem.state as DecimalType) - (setitem.state as DecimalType)
diffitem.postUpdate(diff)
}
else
{
logError("heizung", String::format("SET or DIFF undefined: %s", actitem.name))
}
} else {
logError("heizung", "ACT undefined.")
}
end
And this is the log:
2017-12-16 21:59:45.117 [GroupItemStateChangedEvent] - gActTemp changed from 22.08 to 22.07 through B1HK_ACTUALTEMP
2017-12-16 21:59:45.123 [vent.ItemStateChangedEvent] - B1HK_ACTUALTEMP changed from 21.00 to 20.90
==> /var/log/openhab2/openhab.log <==
2017-12-16 21:59:45.578 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'calc diff temp': null
2017-12-16 21:59:45.593 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'calc diff temp': null
==> /var/log/openhab2/events.log <==
2017-12-16 21:59:45.779 [vent.ItemStateChangedEvent] - B1HK_DIFFTEMP changed from 4.00 to 3.90
2017-12-16 21:59:45.782 [GroupItemStateChangedEvent] - gDiffTemp changed from 2.96 to 2.95 through B1HK_DIFFTEMP
This is the updated rule, works like a charm:
rule "calc diff temp"
when
Item AZHK_ACTUALTEMP changed or
Item AZWT_ACTUALTEMP changed or
Item ArHK_ACTUALTEMP changed or
Item ArWT_ACTUALTEMP changed or
Item B1HK_ACTUALTEMP changed or
Item B1WT_ACTUALTEMP changed or
Item F2HK_ACTUALTEMP changed or
Item FESHK_ACTUALTEMP changed or
Item FEWHK_ACTUALTEMP changed or
Item FEWT_ACTUALTEMP changed or
Item GZHK_ACTUALTEMP changed or
Item KUHK_ACTUALTEMP changed or
Item KUWT_ACTUALTEMP changed or
Item LeHK_ACTUALTEMP changed or
Item LeWT_ACTUALTEMP changed or
Item MiHK_ACTUALTEMP changed or
Item MiWT_ACTUALTEMP changed or
Item SZHK_ACTUALTEMP changed or
Item SZWT_ACTUALTEMP changed or
Item T1HK_ACTUALTEMP changed or
Item TEHK_ACTUALTEMP changed or
Item WZNHK_ACTUALTEMP changed or
Item WZSHK_ACTUALTEMP changed or
Item WZWT_ACTUALTEMP changed
then
val NumberItem actitem = triggeringItem
if (actitem !== null)
{
val NumberItem setitem = gSetTemp.members.filter[i|i.name==String::format("%s_SETTEMP",actitem.name.split("_").get(0))].last
val NumberItem diffitem = gDiffTemp.members.filter[i|i.name==String::format("%s_DIFFTEMP",actitem.name.split("_").get(0))].last
if (setitem !== null && diffitem !== null)
{
var Number diff = (actitem.state as DecimalType) - (setitem.state as DecimalType)
diffitem.postUpdate(diff)
}
else
{
logError("heizung", String::format("SET or DIFF undefined: %s", actitem.name))
}
} else {
logError("heizung", "ACT undefined.")
}
end