[SOLVED] Scale-Transformation in Rule: Error "Could not invoke method: Transformation.transform() on instance: null

  • Platform information:
    • Hardware: Raspberry Pi 4
    • OS: Raspbian 10 (OpenHABian)
    • Java Runtime Environment: OpenJDK 1.8.0_222
    • openHAB version: 2.4.0


I am trying an Example of Marianne Spiller’s german OpenHAB 2 book (Chapter 6.3.5). A Status Summary item is created for wind speed and direction fetched from Yahoo Weather API. I was trying to do something similar with OpenWeatherAPI.


An Item, which works:

Text item=CurrentWindDirection label="Windrichtung [SCALE(windDegreeToText.scale):%s]" icon="wind"

The Summary Item

String SummaryStateWind //wetter.rules

and the rule wetter.rules:

rule "Status Summary Wind"
    Item CurrentWindSpeed changed or
    Item CurrentWindDirection changed
    var Number wg = ((CurrentWindSpeed.state as QuantityType<Number>).floatValue)
    logWarn("wetter.rules","CurrentWindDirection "+CurrentWindDirection)
    logWarn("wetter.rules","CurrentWindDirection.state "+CurrentWindDirection.state)
    logWarn("wetter.rules","(CurrentWindDirection.state as QuantityType<Number>) "+(CurrentWindDirection.state as QuantityType<Number>))
    logWarn("wetter.rules","(CurrentWindDirection.state as QuantityType<Number>).floatValue "+(CurrentWindDirection.state as QuantityType<Number>).floatValue)

    //var wr = transform("SCALE", "windDegreeToText.scale", (CurrentWindDirection.state as QuantityType<Number>).floatValue)
    var wr = transform("SCALE", "windDegreeToText.scale", 240.0f)
    var String Ausgabe = String::format("%1$.0f km/h aus " + wr, wg)

The result of this is

2019-10-10 23:49:10.015 [WARN ] [.smarthome.model.script.wetter.rules] - CurrentWindDirection CurrentWindDirection (Type=NumberItem, State=240.0 ?, Label=Wind direction, Category=wind, Groups=[gWetter])
2019-10-10 23:49:10.022 [WARN ] [.smarthome.model.script.wetter.rules] - CurrentWindDirection.state 240.0 ?
2019-10-10 23:49:10.027 [WARN ] [.smarthome.model.script.wetter.rules] - (CurrentWindDirection.state as QuantityType<Number>) 240.0 ?
2019-10-10 23:49:10.033 [WARN ] [.smarthome.model.script.wetter.rules] - (CurrentWindDirection.state as QuantityType<Number>).floatValue 240.0
2019-10-10 23:49:10.037 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Status Summary Wind': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.core.transform.actions.Transformation.transform(java.lang.String,java.lang.String,java.lang.String) on instance: null

The error occurs no matter which of the “var wr” lines is active. Even the MAP transformation raises the same error. The book example uses a MAP transformation as the Yahoo API delivered different values.
Any idea what I am doing wrong?


Not sure what that is supposed to represent. Try
var wr = transform("SCALE", "windDegreeToText.scale", "240.0")

1 Like

Thank you and sorry for the late reply, I was unexpectedly offline for a time.
The “f” was supposed to represent a float. Anyway, changing it to 240.0 raises exactly the same error. To me, it looks like the transform doesn’t work at all.

Did you use the quote marks? As it says in the error message, the transform() action expects three string parameters.

1 Like

Wow, I didn’t notice the quotes. Yes, that works, so the working line reads:

var wr = transform("SCALE", "windDegreeToText.scale", (CurrentWindDirection.state as QuantityType<Number>).floatValue.toString)

So “on instance null” just means it is a static method, not that something is wrong with the instance?

Thanks a lot, rossko!

1 Like

I’ve no idea of the technical term - practical experience says the rule engine usually means either a non-existent object or some kind of object that cannot be cast to the desired type.