Write Transformation Help

Hi,

i’m in OpenHab 3 (latest Stable) and managed to get the ModBus Binding talking to my Wallbox (Car Charger).

I have one item which holds the limit of current for the charging port.
The Item recieves a value of 110 for 11 Ampere (so needs to be transformed by dividing it by 10 to get the correct value). This works as planned.

But now i want to set the item value to a new current to have the modbus binding sending it back to the wallbox to set a new maximum current value.

If i want to set the maximum current to lets say 32 Amps i need to send a value of 320 to the wallbox via modbus.

I’ve added a slider widget to the ui and attached it to the item holding the current amps value. The Slider shows the human readable amps reported by the wallbox via modbus (and so the value of the item).

I now tried to set the Write Transform of that item as follows:

JS:(|input * 10)

but this doesn’t seem to work. The value sent to the wallbox is still “32” and not “320”. I’ve thought the connected slider would send a value of 32, the Write Transform Rule would multiply it by 10 and send this tot the modbus?

Is there something wrong with the Write Transform Rule? If i slide to “18”, the wallbox seems to recieve “20” and sets the current for the outlet to 2 Ampere.

Here is my tidel.js.
Remember to install javascript binding

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

From Modbus.things

Thing data input_3014 [ readStart="3014", readValueType="uint16", readTransform="JS(tidel.js)"]

I’ll try that. Read - Transform works directly as formular in thing definition. Will try as file in write Transformation.

I believe the Modbus add-on comes with a custom offset Profile that can add/subtract/multiply/divide the value before it gets to the Item. You don’t need to code this in a JS transform.

1 Like

Thanks for this hint! That did the trick. No Javascript Transformations needed.
Saved me a lot of time.

Regards BoxSon

I should have noted that the offset profile built into core is being updated to support multiplication and division too so the modbus add-on provided one should no longer be needed. Hopefully it’ll be merged before OH 4.0 release.