I am still pretty new to openhab and I made good progress so far in using it to read data from my Huawei solar inverters and battery stack.
However, I ran into one issue with data read from the Luna2000 battery that is giving me problems and I would like to know if you could point me in a direction.
Whenever the battery is offline (e.g. at night), the charge/discharge register alters between “0” and “2147483647”. In Grafana, I can force visualization to convert the maxed INT32 value to “0” for display purposes. This does not however cure the problem in the database where these values make it impossible to use the alternating modbus output for any sensible calculations.
Is there a quick and easy method to transform “2147483647” to “0” when receiving data from the register?
Hey, thanks for pointing me towards scripts. I tried using rules with an attached script here but it obviously doesn’t work as intended because the rule execution doesn’t catch all the results.
//if Battery is off
if(itemRegistry.getItem('ModbusData37001ESU1ChargeandDischarge_ValueasNumber').getState() == 2147483647)
{
events.postUpdate('ModbusData37001ESU1ChargeandDischarge_ValueasNumber',0);
}
Yes, I’ll try to place it inside the /transforms folder.
Can I name the number “2147483647” explicitly in the code fragment and have it transformed to “0”? In my case, I’m not dealing with negative numbers but with only one huge positive number.