- Platform information:
- Hardware: Raspberry Pi 4
- OS: Raspbian 10 (OpenHABian)
- Java Runtime Environment: OpenJDK 1.8.0_222
- openHAB version: 2.4.0
Hello,
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.
Transformation:
windDegreeToText.scale
[0..22.5]=Nord
]22.5..67.5]=Nordost
...
[..]=undefiniert
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"
when
Item CurrentWindSpeed changed or
Item CurrentWindDirection changed
then
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)
SummaryStateWind.postUpdate(Ausgabe)
end
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?
Thanks
Marcel