I read DC power data (Register 30773 ) from my SMA SunnyBoy3.0 Inverter via the modbus binding in OH5.0.2.
During the day that works fine, but at night it seems the inverter instead of zero returns crazy negative values (-2147483648 W). Now I would like to set negative values to zero before they end up in persistance.
I read that I could accomplish that maybe with a rule ([SOLVED] Convert an item negative value to 0 (zero)), but somehow this seems to be a rule running all the time and I am not sure if in persistence then the value would flip between zero and minus all the time. Is there also a way to accomplish that by setting a Read Transform? I couldn’t get my head around how read transforms work from the documentation…
I added “JS(sb3NotNegative.js)” in the UI as value for the Read Transform in the string and created a file in the file system by cd $OPENHAB_CONF/transform with the content:
(function(data) {
// Do some data transformation here, e.g.
if(data<0)
data=0;
return data;
return "String has" + data.length + "characters";
})(input);