SNMP binding and JS transformation

I would like to transform data fetched by SNMP binding from my ups.
Data should be divided by 10. It comes from UPS as a number but knowing that js transform returns string i changed number to stirng in thing and item def.
Tried adding transform in thing file, items file and both. Nothing works and there is no errors in the logs. Data is still showing as original without transformation.
I am pretty sure that this transforms worked with v1 binding.

Here are my files:

divide_by_10.js

(function(i) {
    return parseFloat(i) / 10;
 })(input)

snmp.items

String  UPS_HighPrecOutputEfficiency     "Output eff. [JS(divide_by_10.js):%s]"                              { channel="snmp:target:apc_ups:UPSHighPrecOutputEfficiency" }

snmp.things

Type string : UPSHighPrecOutputEfficiency		  [ oid=".1.3.6.1.4.1.318.1.1.1.4.3.5.0", mode="READ", readTransform="JS(divide_by_10.js)" ]

Any help would be appreciated.

Maybe I missed it, but are you sure that the SNMP Binding has an option for transforming at the Channel level? I can’t see your readTransform anywhere in the docs.

The fact that there is no error in the logs is a little strange. What happens if you remove your JS file - does openHAB complain then?

I had the same issue some days ago when migrating from v1 to v2.

What worked in my case was defining the transformation as a channel profile in the items file. Check out the JS transformation addons docu where you can find an example.

Thx, that’s solved the problem :slight_smile: