Divide KNX item value by 1000


can you help me to divide an item by 1000? I’m struggling with the syntax here I think:


Type number: PWR_Hzg_ZaehlerGes “PWR Heizung Gesamtverbrauch” [ga=“13.001:<3/7/100”]


Number PWR_Hzg_ZaehlerGes “Stromzähler Wärmepmpe [JS(divideBy1000.js):%s kWh]” { channel=“knx:device:bridge:generic:PWR_Hzg_ZaehlerGes”}


(function(i) {
return parseFloat(i) / 1000;

the division works, but how can I show the number with two decimals? Also on PaperUi shows the item value as “JS(divideBy1000.js):130kWh”


Just add toFixed(num_of_decimals)

Thanks. It worked, although it seems that PaperUI can’t show the transformed value under the default “Control” section.

That is perfectly right if you added the transformation to the sitemap. The control page is more or less to show that the item you have setup is working.

why this is not showing anymore the specified unit “kWh”? the division works, but in the sidemap i am missing the units! If puting there again “value [%s kWh]” … i get the value without the division…

You should use [%.3f kWh] because the value is a float the 3f means three digits behind the decimal point, so you could also use [%.1f kWh] for one digit.
If you want a number without decimals [%d kWh] do not use [%s kWh] that is for text.

its not working! the unit will be ignored if you use the javascript to change decimal point…

umber inverter1ActivePower           "Aktuelle PV-Produktion [JS(divide1000.js):%.3f kWh]"           <solarplant>	    (gSMA)             {channel="modbus:data:inverter1:Active_Power:active_power:number"}

output is without “kWh”, only the correct value now in kW not more in W

Just change your JS to something like this. Add the unit after all your calculations

;(function (i) {
    var recVal = parseFloat(input)/1000
    return recVal + ' Watt'

Thanks great! its working!