Simple + calculation in items (?)

Hi, i have two photovoltaic power plants that i would like to see as a single value in the GUI…is there a very simple way to do such + calculation directly in items…so not to force another rule for this?
And if rule is required…how would that work? wait if one of the two is updated an do the calculation in another number variable?

Thanks, Norbert

You would need a rule if the inputs are the DecimalType states of two items, and the output is the sum of those two Number items:


Number InputA
Number InputB
Number Total


import org.openhab.core.library.types.DecimalType // not needed on OH2
rule SumTwoInputs
  Item InputA changed or
  Item InputB changed
  if (InputA.state instanceof DecimalType && InputB.state instanceof DecimalType) {
    Total.postUpdate((InputA.state as DecimalType) + (InputB.state as DecimalType))
  } else {
    Total.postUpdate(Undefined)  // or UNDEF on OH2

very cool, thanks Watou…this code makes my life easy.
I feared that the openhab concept would strictly split items from anything like calculation…

So this code also solves troubles through undefined/non-decimal values. great

1 Like

it’s valid also for subtraction?

rule SottrazioneProduzione
  Item SolarLogMeter_YieldDay changed or
  Item SE5000_Day_Production changed
  if (SolarLogMeter_YieldDay.state instanceof DecimalType && SE5000_Day_Production.state instanceof DecimalType) {
    Sma5000_Day_Production.postUpdate((SolarLogMeter_YieldDay.state as DecimalType) - (SE5000_Day_Production.state as DecimalType))
  } else {
    Sma5000_Day_Production.postUpdate(Undefined)  // or UNDEF on OH2

What about group sum ?