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?
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:
items:
Number InputA
Number InputB
Number Total
rule:
import org.openhab.core.library.types.DecimalType // not needed on OH2
rule SumTwoInputs
when
Item InputA changed or
Item InputB changed
then
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
}
end
rule SottrazioneProduzione
when
Item SolarLogMeter_YieldDay changed or
Item SE5000_Day_Production changed
then
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
}
end