Rules consider a item as NULL but items list does not

Running Openhab 3.4.2 from Debian package,

In a rule, I put only this :

var QuantityType tempCompTest = (LocalWeather_ForecastTonight_MinimumTemperature.state + 3|°C)
logInfo("Value : ", tempCompTest.toString);

Triggering the rule, I face :

[ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘onParentsRoomTemperatureChange-1’ failed: An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null in onParentsRoomTemperatureChange

But from the console, I have :

items list | grep LocalWeather_ForecastTonight_MinimumTemperature
LocalWeather_ForecastTonight_MinimumTemperature (Type=NumberItem, State=3.72 °C, Label=Température minimale de la nuit, Category=temperature, Groups=[Weather])

Where is the NULL ? (This rule has been working flawlessly for years before 3.4)

Thanks for reading and sorry in advance @rikoshak : I will say “but of course…” once you’ll have answered :blush:

(edited to reduce the problem on advice of Matthias)

You are working here with two items, but only have shown that you have tested one of them.
What about the other item? Most likely it also has a UoM .

Of that’s not helping, as a workaround you can try to store both values into variables first, maybe that’s helpful to see where the error is coming from.

Thanks Matthias for your interest.
You are right, I should have reduced my problem. This is now done (directly in the first post).

Even if I don’t understand why, I figured it out.
I need to add “as QuantityType” now to have the rule working in 3.4.

var QuantityType tempCompTest = (LocalWeather_ForecastTonight_MinimumTemperature.state as QuantityType + 3|°C)
logInfo("Value : ", tempCompTest.toString);

Not a great progress for rules tinyness :blush:

When Rules DSL cannot figure out how to convert one of the operands to an operation to be compatible with the other, it gets a null error like this. It doesn’t mean that the operand is actually literally null, but after attempting to cast or manipulate the state Rules DSL ended up with null.

How Rules DSL does this is it takes the first operand as the base type and it only tries to manipulate the second operand.

The type of LocalWeather_ForecastTonight_MinimumTemperature.state is State. State doesn’t support operations like +. It’s trying to convert the + to become a String (which is why it’s trying to use operator_plus(Object, String)) but can’t convert 3|°C to a String and therefore fails with null.

I bet it will work if you swap the operands.

3|°C + LocalWeather_ForecastTonight_MinimumTemperature.state 

or tell it that the state is a QuantityType.

LocalWeather_ForecastTonight_MinimumTemperature.state as QuantityType<?> + 3|°C
1 Like