Rule error: Instance null even though it has a value

Hi,

I can’t seem to figure out why this won’t work in a rule:

		var Number gpsacc  = transform("JSONPATH", "$.gps_accuracy", json)
		logInfo('Presence','Acc: ' + gpsacc) 
		if (gpsacc < 50) {
                    logInfo('Presence','test')
                }

This throws the following error:

An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.lib.NumberExtensions.operator_lessThan(java.lang.Number,java.lang.Number) on instance: null

But the "logInfo(‘Presence’,'Acc: ’ + gpsacc) " clearly outputs a number:

[org.eclipse.smarthome.model.script.Presence ] - Acc: 22

Why does the rule say it’s “null” ??

It’s most likely because your transform returns a string and no Number.

Try to change to:

var Number gpsacc  = Integer::parseInt(transform("JSONPATH", "$.gps_accuracy", json))
2 Likes

Thank you, that fixed it. I was under the impression that by defining it as a number it was converted to a “number” or integer type.