How to transform bit/s to mbit/s in a channel / item


i am using the snmp-binding to get the actual bandwith from my modem. I get the value as bit/s but would like to transform it to mbit/s and am not sure how to convert it the right way.
Would be great if anyone could help me.

Thanks, Alex

I’m using Javascript Transformation to do something similar. I have IKEA Tradfri rollershutter which reports battery in the 0-50 range, so I created transformation for that channel that doubles the value. The code for the .js file looks like this:

(function(i) {
    return 2*i

Thanks for your reply! I am not really familiar with JS but i tried to adopt your script for a first test…

(function(i) {
    return i/1000

After that i changed the profile at the channel link but i get this warning:

12:39:55.181 [WARN ] [files.JavascriptTransformationProfile] - Could not transform state '86154000' with function 'calc_bandwidth.js' and format '%s'

Actually the Value of the item is 86154000 and i want to get 86,2 mbit/s

There seems to be problem with formatting the code, those three apostrophes shouldn’t be there at the end. Try this:

(function(i) {
    return i/1000
1 Like

Thank you, great! Now i get 86 as value for the item.
When i add

%.1f MBit/s

to the state formatter at the advanced options i get an error again. When i add it to the state description the value is shown as expected:

I’m not sure what “advanced options” you are looking at,but maybe the / needs escaping there //.
EDIT - ah wait, are talking about the profile? JS profile returns strings (even if it looks like a number) so can’t be formatted with numeric %.1f until after it has been used to update a Number Item.

As an aside, shouldn’t you be dividing by 1024?


yes, in principle you are right. I actually have to divide once by 1024 and once by 1000. The last three zeros are apparently only appended by the modem.

(function(i) {
    return i/1000/1024

Does someone know how to reset the persisted values by OH3? I havent setup a persistance service, yet, but i would like to reset the data that is safed by default:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.