Modbus combined registers

I come over ISG integration which is based on modbus binding. Sadly, combination of Stiebel components I got to work with is not well covered by modbus-isg. I had to revert to traditional register based play.

Problem which I face currently is joining two registers:

reg id|  dec | hex
[3524]|  908 | 0x038C
[3525]|   44 | 0x002C

These two are presented as 908 kWh and 44 MWh. Final number is 44,908 MWh.
I had a look on available number formats (int32/uint32/float32 with swap) and I haven’t found any way to join above two into a desired number.

I’d appreciate any advice how to get it over.

Inside plain modbus binding ? Now come on, that it’s not built for.
Or did you mean to say you expect this functionality from the modbus-isg integration (that I don’t know)?

Why don’t you just do the math inside rules ?

1 Like

I would like to avoid creation of 3 items (kwh, mwh, merged result) just to process single energy reading. Given the nature of modbus polling and items I think I’d get double updates. One for MWh part, other for KWh putting additional load on system.
Given that registers are neighbors I’ll read register 3524 and 3525 as uint32 and then do math in the profile. This will spare me two extra items at the cost of little code to maintain:

      DecimalType mergedReading = (DecimalType) reading;

      int scaledValue = mergedReading.toBigDecimal().intValue();
      int mwh = scaledValue & 0xffff;
      int kwh = (scaledValue >> 16) & 0xffff;

      QuantityType<Energy> energy = QuantityType.valueOf(mwh, Units.MEGAWATT_HOUR)
        .add(QuantityType.valueOf(kwh, Units.KILOWATT_HOUR));
      profileCallback.sendUpdate(energy);

I’ll publish complete code so others with similar issue could use it in their setups. :wink:

Cheers,
Łukasz

1 Like

Actual code can be located here: