i am frustrated because i try several hours to transform modbus data on OH4.0.2
OH runs on docker on a synolgy diskstation.
the javascript and modbus binding/addon is installed
i can receive the values for example the value 2141.
this is the voltage of the battery of my pv and is “214.1 V”
i don not know how to transform it.
at last i tried to create a java script file in the transform folder.
divideby10.js:
// Wrap everything in a function (no global variable pollution)
// variable “input” contains data passed by openHAB
(function(inputData) {
// on read: the polled number as string
// on write: openHAB command as string
var DIVIDE_BY = 10;
return parseFloat(inputData) / DIVIDE_BY;
})(input)
but it won’t work.
can anyone please explain how to divide the value by 10
I also tried to use an inline javascript code in the “Read Transform”:
The modbus binding comes with an offset profile that lets you add a constant, multiply/divide by a constant, and apply a unit to the data. You can apply it on the link between the Item and the Channel.
Beyond that, which JavaScript binding did you install, Nashorn or JS Scripting?
It might be easier for you to use the UI to create the transformation: Settings → Transformations.
Those four words contain an infinity of possibilities. Won’t work how? Errors in the log? Do not appear to run at all? What?
The inline can be a bit finicky. You might need to add a space after the “|”.
The “JavaScript Scripting” has been installed, not the nashorn.
I created an divideBy10.script file in transformations.
then i selected “SCRIPT ECMAScript (ECMAScript 262 Edition 11)” in the profile and selected my “divideBy10.JS”
I also tried the JS inliner in the same place.
JS:| parseFloat(input)/10
There was already a space inserted. The space was only left in my quote in this thread.
But it does not change the displayed value. I still get an undivided integer.
I selected the same profile type. Was that the mistake? Should i select an other type?
The thing itself has an “Read Transform” but i do not find any helpful information how to use a transform in the thing itself.
I also tried to install a new openhab 4.2.0 with openhabian on an raspberry 2b. But i only receive one value at one time with different time distances.
I selected an update intervall of 10000ms (10s) for all polls but i only get one single value every 10 seconds.
On my diskstation i get every 10s a value for all items.
I suppose the raspberryPi 2b ist to slow for openhab with an modbus binding? ist that right?
Does anyone has experience with an raspberry pi 2b and network?
The JS is already assumed since you selected that. It should be just:
|parseFloat(input)/10
Try it both with and without a space after the “|”.
Don’t use quotes when posting code. Use code fences.
```
code goes here
```
I don’t know the modbus binding but you would apply a transform there the same as you would in a profile. Only there isn’t a nice selection option. You’ll have to type it in, meaning to use the file you would use JS:divideBy10.js or JS:| parseFloat(input)/10.
I can’t help with that.
In general, an RPi 2b is too slow to run OH 4 with any configuration. As of OH 3 the minimum RPi supported was an RPi 3 and with OH 4 the minimum recommended is an RPi 4 with at least 4 GB RAM. You might get lucky enough to run OH 4 on an RPi 3 but your system needs to be 32 bit and very minimal.