I have this rule:
// ----- 170406 MaxG; total grid profit / loss
rule "Grid profit and loss12"
when
Item spp_Date changed or
// s m h D M Dow Y
Time cron "0 0/1 * * * ? *"
// here every minute
then
logInfo("ProfitLossTotal.rule", "spp_ProfitLoss...............: {}", spp_ProfitLoss)
var Number spp_ProfitLossTotal.state = 9.96
//spp_ProfitLossTotal.state = 9.96
logInfo("ProfitLossTotal.rule", "spp_ProfitLossTotal.1........: {}", spp_ProfitLossTotal)
spp_ProfitLossTotal.postUpdate(spp_ProfitLossTotal += spp_ProfitLoss)
logInfo("ProfitLossTotal.rule", "spp_ProfitLossTotal.2........: {}", spp_ProfitLossTotal)
end
Since the spp_Date only changes once every morning around 0600, I wanted to see, if my rule actually works, so I added the cron definition.
Since spp_ProfitLossTotal is uninitialised (first use ever; it is defined in .items as Number) I set it to 9.96 – so I do not need an if(null) statement.
Once the rule would have run once, I would remove this line as ProfitLossTotal is now initialised and persisted.
What the rule should do: if the spp_date has changed add to spp_ProfitLossTotal the value of spp_ProfitLoss – to tally the daily ProfitLoss.
When I use
spp_ProfitLossTotal.state = 9.96
I get this error:
// 2017-04-07 10:13:00.364 [INFO ] [.m.script.ProfitLossTotal.rule] - spp_ProfitLoss...............: spp_ProfitLoss (Type=NumberItem, State=-0.59)
// 2017-04-07 10:13:00.544 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Grid profit and loss10
// java.lang.IllegalStateException: Could not invoke method: org.openhab.core.items.GenericItem.setState(org.openhab.core.types.State)
// on instance: spp_ProfitLossTotal (Type=NumberItem, State=Uninitialized)
When I use:
var Number spp_ProfitLossTotal.state = 9.96
I get no error, but since the two following log entries do not occur, I know that the rule is not continuing.
The issue I see with the line above is, it may be a double definition, since spp_ProfitLossTotal is defined as an item. I certainly can’t get rid of it, as I need it to display on the sitemap.
I fI use:
spp_ProfitLossTotal.postUpdate(new DecimalType(9.96))
I get:
2017-04-07 10:35:00.027 [INFO ] [.m.script.ProfitLossTotal.rule] - spp_ProfitLoss...............: spp_ProfitLoss (Type=NumberItem, State=-0.59)
2017-04-07 10:35:00.066 [INFO ] [.m.script.ProfitLossTotal.rule] - spp_ProfitLossTotal.1........: spp_ProfitLossTotal (Type=NumberItem, State=9.96000000000000085265128291212022304534912109375)
2017-04-07 10:35:00.188 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Grid profit and loss12
java.lang.RuntimeException: The name '<XFeatureCallImplCustom> += <XFeatureCallImplCustom>' cannot be resolved to an item or type.
This is one of those rules, which are dead simply, yet puzzle me to the point of annoyance, because it does not work.