Get KNX percentage value and show as item

From a KNX device, I get a percentage value [0…1], which should be shown in an item in OH3.2 as [0…100%]

What I did so far

  1. Multiplied the channel value by 100

Added the JavaScript function in transform folder as “MultiplyBy100.js”

(function(i) {
var nVal = parseFloat(i) * 100;
return nVal.toFixed(2)
  1. Added an item

  2. But how to convince the item to show the percentage value correctly?

I tried Pattern "%s %%". It shows “4 %”, but with an error message
Could not transform state '4' with function 'JS:transform/MultiplyBy100.js' and format '%s'.

From a recent post, I found hints regarding JavaScript returns a String only:

This has been improved for OH3, the profile framework should now attempt to parse the transform’s string output into the Item type, e.g. “3.0” should be usable with a Number Item, just as you can do someNumber.postUpdate("3.0") and expect the framework to parse it.
This new feature should be included in the milestone

why not use a dimmer ?

The output of the javascript that you are using in your transform profile is numeric only.
If you want that to be a percentage in your Number:Dimensionless type Item, you’ll need to append the units string " %" to your javascript result before returning it.

I don’t think that’s the source of the error though. When showing ius error messages, please show the whole log line as it includes some hint about message source.

What KNX channel type are you starting from?

Adding the item type to dimmer → error message is gone. Thx.

The KNX channel type is “number” with group adress 5.001:10/5/30, no other log message entry.

What is challenging for me: it took 6 hours so far to handle that percentage character issue.
It seems that everything depends on everything…

    if changed, restart is necessary. No hint in the UI, only in the KNX binding docs
  • KNX channel type
    which can´t be changed
  • Item type
  • Item profile
    Following rossko57´s advice - I played with the Javascript, added the " %" before returning.
    Weird is that the changed script is not reliably recognized even after restarting openhab.
    Isn´t there some file system checking implemented to update any cache? Why is it file system based and not integrated in the UI?
    Gave up with that one, too complicated at the moment
  • Item state description
  • In the item overview, the percent is not shown, but in the details (see below)
  • Quite confusing is the amount of (outdated) forum entries, which refer to OH 2.5 or early releases of OH3

Summary for future seekers

Are there any KNX related how to´s, which are open for contributors?

Type number        : humidity_soil           "humidty "    [ ga="9.001:<7/3/0" ]

Number:Dimensionless Humidity_value "Humidity [%s %%]" <humidity> (g_general) ["Measurement", "Humidity"] {channel="knx:device:bridge:knx:humidity_soil"}