Problem with converting from m/s to km/h

Hi there,

i have a Problem with the JS Transformation. I like to show my windspeed in km/h in my basic UI. I get it to show the value, but if i add km/h in the definition, it shows “NaN”.

Thing Definition

Type number         : Windspeed                       "Windgeschwindigkeit"                 [ga="9.005:<6/1/149"]

Item Definition

Number          Windgeschwindigkeit             "Windgeschwindigkeit [%.2f m/s]"                    <wind>          (Weather)               {channel="knx:device:bridge:wetterstation:Windspeed", autoupdate="false" }


Default     item=Windgeschwindigkeit label="Wind [JS(windspeed.js):%.2f km/h]"
Default     item=Windgeschwindigkeit label="Wind [JS(windspeed.js):%.2f]"
Default     item=Windgeschwindigkeit



    return i*3.6;


What i have to do to get a nice km/h value :slight_smile:

A state transformation used in a label always returns a string.
You cannot format a string with %.2f even if it looks like "2.35’, it is not a float.
[JS(windspeed.js):%s km/h]

Changed it to (tried beforce)

Default     item=Windgeschwindigkeit label="Wind [JS(windspeed.js):%s km/h]"

Also gets me “NaN”. Also when i change the “Default” Item definition to “Text”

But now the NaN comes from your script.
The Item state is passed into the javascript as a string, too, so you’d need to parse that before doing maths.

return parseFloat(i) * 3.6;

1 Like

Thank you. The NaN is gone but km/h does not show up. And the Number doesnt get rounded…

Hi there,

i got a solution. Modified my JS Transition to

    return kmh.toString() +" km/h";

Item Definition

Number			Windgeschwindigkeit             "Windgeschwindigkeit [%.2f m/s]"                    <wind>			(Weather)               {channel="knx:device:bridge:wetterstation:Windspeed", autoupdate="false" }

The Sitemap Definition is like

Text		item=Windgeschwindigkeit label="Wind [JS(windspeed.js):%2f]"

No, it’s up to you have your script do that.