JS transform as a profile (in .items file) gives error

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: openhabian
    • Java Runtime Environment: Default openhabian
    • openHAB version: 2.5.0~M1-1
  • Issue of the topic: Using JS transform as a profile gives log error

I have a water level sensor that returns the distance of the surface to the sensor as its value, and now in OpenHab I want to create an item that holds the water level in percent (calculated from that distance). I’m using text files only:

Number	Wasserstand_Wohnzimmer	"Wasserstand [%d mm]"		<water>	{ channel="mysensors:distance:gateway:Wasserstandssensor_Wohnzimmer:distance" }
Number	Wasserlevel_Wohnzimmer	"Wasserlevel [%d %%]"		<water>	{ channel="mysensors:distance:gateway:Wasserstandssensor_Wohnzimmer:distance"[profile="transform:JS", function="waterlevel.js", sourceFormat="%f"] }

waterlevel.js:

(function(x){
    var result;
    var minLevel = 50;
    var maxLevel = 300;
    result = (maxLevel - x)/(maxLevel - minLevel)
    // Make sure the percentage is in 0-100%
    result = min(1, max(0, result))
    return result;
})(input)

While Wasserstand_Wohnzimmer works fine and holds the distance of the surface to the sensor, the level item does NOT work, but gives a log error:

12:31:43.949 [INFO ] [smarthome.event.ItemStateEvent       ] - Wasserstand_Wohnzimmer updated to 102
12:31:43.952 [WARN ] [files.JavascriptTransformationProfile] - Could not transform state '102' with function 'waterlevel.js' and format '%f'
12:31:43.958 [INFO ] [smarthome.event.ItemStateChangedEvent] - Wasserstand_Wohnzimmer changed from 105 to 102

I tried searching here for possible solutions, but only found other users that have the same problem, but without any solution. Am I using the profile feature wrongly?

There is a post here that seems to indicate that the JS transform always returns a string (really?) and that OpenHab simply does not work with this yet, but would need an additional conversion of the value returned by the transformation. Is this correct? If so, how can I make the JS transformation work with my .js script?

Thank you a lot!