Hi everyone, I have a problem with the transformation of an item.
I am getting weather data from the (quite) undocumented DWD Weather API that spits out JSON formatted Data. I am trying to extract the predicted minimum and maximum temperatures and the rainfall of today and tomorrow. These values are in 0.1°C and 0.1 mm, so a value of for example 150 in the JSON corresponds to 15.0°C. I would like to transform these values by dividing them by 10 to have the correct values in the Items.
My http.things file to get the values:
Thing http:url:DWDWetterHGW "Wetterdaten aus der DWD API" [
baseURL="https://dwd.api.proxy.bund.dev/v30/stationOverviewExtended?stationIds=10184",
refresh=300
]{
Channels:
[stateTransformation="JSONPATH:$.10184.forecast1.precipitationTotal"]
Type string : VorhersageHeuteTempMin "Vorhersage heutige Minimaltemperatur in °C" [stateTransformation="JSONPATH:$.10184.days.[0].temperatureMin"]
Type number : VorhersageHeuteTempMax "Vorhersage heutige Maximaltemperatur in °C" [stateTransformation="JSONPATH:$.10184.days.[0].temperatureMax"]
Type number : VorhersageHeuteNiederschl "Vorhersage heutiger Niederschlag in 0,1mm/d" [stateTransformation="JSONPATH:$.10184.days.[0].precipitation"]
Type number : VorhersageMorgenTempMin "Vorhersage morgige Minimaltemperatur in °C" [stateTransformation="JSONPATH:$.10184.days.[1].temperatureMin"]
Type number : VorhersageMorgenTempMax "Vorhersage morgige Maximaltemperatur in °C" [stateTransformation="JSONPATH:$.10184.days.[1].temperatureMax"]
Type number : VorhersageMorgenNiederschl "Vorhersage morgiger Niederschlag in 0,1mm/d" [stateTransformation="JSONPATH:$.10184.days.[1].precipitation"]
}
My http.intems:
Number:Temperature DWDWetter_HGW_VorhersageHeuteTempMin "heutige Min Temp [%.1f °C]" {channel="http:url:DWDWetterHGW:VorhersageHeuteTempMin"[profile="transform:JS", function="| input / 10"]}
Number:Temperature DWDWetter_HGW_VorhersageHeuteTempMax "heutige Max Temp [%.1f °C]" {channel="http:url:DWDWetterHGW:VorhersageHeuteTempMax"[profile="transform:JS", function="| input / 10"]}
Number:Speed DWDWetter_HGW_VorhersageHeuteNiederschl "heutiger Niederschlag [%.1f mm/d]" {channel="http:url:http:url:DWDWetterHGW:VorhersageHeuteNiederschl"[profile="transform:JS", function="| input / 10"], unit="mm/d"}
Number:Temperature DWDWetter_HGW_VorhersageMorgenTempMin "morgige Min Temp [%.1f °C]" {channel="http:url:DWDWetterHGW:VorhersageMorgenTempMin"[profile="transform:JS", function="| input / 10"]}
Number:Temperature DWDWetter_HGW_VorhersageMorgenTempMax "morgige Max Temp [%.1f °C]" {channel="http:url:DWDWetterHGW:VorhersageMorgenTempMax"[profile="transform:JS", function="| input / 10"]}
Number:Speed DWDWetter_HGW_VorhersageMorgenNiederschl "morgiger Niederschlag [%.1f mm/d]" {channel="http:url:DWDWetterHGW:VorhersageMorgenNiederschl"[profile="transform:JS", function="| input / 10"], unit="mm/d"}
The transformation with JavaScript I copied from a posting from Rich Koshak in another Topic
In my case it does not work though. I get the following Error:
[.module.script.profile.ScriptProfile] - Neither 'toItemScript' nor 'toHandlerScript' defined in Link 'DWDWetter_HGW_VorhersageHeuteTempMax -> http:url:DWDWetterHGW:VorhersageHeuteTempMax'. Profile will discard all states and commands.
When searching for the Error message, I found this thread. Here the transformation is handled in a .js file, which I would like to skip to keep things simple, because there seems to be the inline transformation that Rich suggested.
I’m currently running OH 4.1.3. I have tried restarting the VM (Ubuntu 22.04) and restarting OH, neither of this fixes the problem. The Items get filled with the “correct” data (150 in the example case) if I delete the “[profile=“transform:JS”, function=”| input / 10"]". Other Items in the .items file function as they should.
What could be the problem here?
Short workaround for the Temperature (that I don’t intend to keep):
One can use the SI-prefix “deci” (d) also in addition to °C (somehow obvious but I have never encountered deci°C in the wild). This does not work for the rainfall because the next smaller si-prefix from mili (10^-3) is mikro (10^-6) but I would need 10^-4.