Hi,
i have a smartmeter inside a small box connected to my car. while charging I send MQTT messages. like absolute kwh, voltage, amps,…
Now a rule makes problems that the EVchargeWhImp (absolute kwh at the meter) often is NULL when unplugged an openhab got resetted…and i wanted the rule to check if NULL and so skip the rule and next time when MQTT is sent another time the NULL got overwritten and all is fine and rule can be processed… Should the NULL-killer work like this? >>>> EVchargeWhImp.state != NULL <<<<<<
rule "ChargeStart Detection"
when
Item EVchargePower received update
then
if ((EVchargePower.state > 1000) && Car_Charging.state != ON && EVchargeWhImp.state != NULL)
{ Car_Charging.sendCommand(ON)
EVchargeStartMeter.postUpdate(EVchargeWhImp.state as DecimalType)
}
end
Ifs are evaluated from left to right. With ANDs the evaluating stops at the first case that is not true.
I would think that a small reordering will fix the problem:
So with NULL (undefined)…i have to use != …and not !== ??
But isn’t the order in the IF or completely irrelevant for the performance…or you mean that if the NULL part is checked … it would immediately close the IF branch and not go through the rest, is that the intention of different order in the if?
That’s it. So it will then avoid generating an error when, say, trying to convert NULL to a number in order to compare with another number.
Technically the if() test has to be completed at that point. if (X is true) AND (Y is true)
If X turns out to be false, there is no need to even look at Y if (X is true) OR (Y is true)
If X turns out to be false, we must still look at Y to solve the whole statement