I’m getting an error that I’m not sure how to fix?
2020-03-27 11:10:58.622 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘LilyRuleTemp’: Could not cast NULL to java.lang.Number; line 7, column 50, length 31
rule "LilyRuleTemp"
when
Item LB_Temperature changed
or
Item LB1_Temperature changed
then
var t = ((LB_Temperature.state as Number) + (LB1_Temperature.state as Number)) / 2
Lilys_Bedroom.postUpdate(t)
end
All Items start life with a state NULL.
You cannot cast that to Number, etc.
You can avoid trying to do that sort of thing
then
if ( LB_Temperature.state != NULL && LB1_Temperature.state != NULL) {
var t = ((LB_Temperature.state as Number) + (LB1_Temperature.state as Number)) / 2
Lilys_Bedroom.postUpdate(t)
} else {
logInfo("LBtemprule", "Unexpected NULL value")
}
end
Rather than using a rule, you might want to try using group aggregation. Define Lilys_Bedroom like Group:Number:AVG. Then add the other temperature Items to it. The group will calculate the average for you.
i am having the same problem but i cannot solve it.
In the logs i saw the error:
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Jalousien-4' failed: Could not cast NULL to org.openhab.core.library.types.OnOffType; line 64, column 37, length 48 in Jalousien
Then i tried to only send the update if it is not NULL:
rule "Status Automatische Beschattung (An/Aus) alle 5 Minuten senden"
when
Time cron "0 0/5 * * * ?" // alle 5 Minuten
then
var freigabedummy = Haus_Automatische_Beschattung.state as OnOffType
if(Haus_Automatische_Beschattung.state != NULL)
{
sendCommand(Haus_Automatische_Beschattung,freigabedummy)
}
end
But it does not work.
I still get the same errors in the log.
Basically i want to send the value periodically (some kind of persistence for my knx installation).
rule "Status Automatische Beschattung (An/Aus) alle 5 Minuten senden"
when
Time cron "0 0/5 * * * ?" // alle 5 Minuten
then
var freigabedummy = ON
if(Haus_Automatische_Beschattung.state != NULL)
{
freigabedummy = Haus_Automatische_Beschattung.state as OnOffType
Haus_Automatische_Beschattung.sendCommand(freigabedummy)
}
end