Number:Speed
expects any valid speed quantity you like - 30mph if you wish.
Also, if you declare a default unit in the Item metadata, you can post just-a-number with no units as the KNX binding does. The plain number will be assumed to be in default units.
So you use Item metadata ‘pattern’ to declare that default unit, this is very like the sitemap [state presentation]. Set it to %.1f m/s
In MainUI your Item state should now get shown as “10.0 m/s”. But you don’t care about that if you are using sitemaps.
In your sitemap widget, use a label="Whatever [%.2f km/h]"
and the framework will automatically convert state m/s to km/h for display.
No transformation required, but its “cheating” a bit
So, the “proper” way instead.
Number:Speed
expects any valid speed quantity you like - 30mph if you wish.
KNX channel only supplies a numeric - but we can append a unit (assuming we know what comes from KNX device).
Profiles attach to the link between channel and Item, and can manipulate states before they get to the Item - just what we want. We can use a JS javascript transform to append the units text.
First install JS transformation service (nothing to do with scripting)
Then use your favourite text editor to make a little javascript file in your /transform folder.
Give it a file name like addms.js
// input variable i contains data passed by OpenHAB binding
(function(i) {
if (i == 'UNDEF') { return i; } // pass through non-numeric
else { return i + ' m/s' ; }
})(input)
Add a JS transformation profile to your channel-Item link, pointing at your new addms.js file.
Now your Item state should be updating like 10m/s. But you wanted it in km/h … so you have to tell it.
Use Item metadata ‘pattern’ to declare that a unit, this is very like the sitemap [state presentation]. Set it to %.2f km/h
.
The 10m/s update should now be seen in MainUI as 36.00 km/h
Put what you like in sitemap widgets, and auto conversion will happen as required.
There are other options that are not available to you as an OH 3.1 user, same principle but avoiding the little script file.