We have a two installation of solar that I would like to see the total together.
In the update status of both, I want to do a calculation of both to another number
rule “Total Day update time”
when
Item Patronus_Day_Energy received update
then
postUpdate(Solar_Day_Energy, Patronus_Day_Energy+3)
end
I get a message that Patronus_Day_Energy is null
An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
postUpdate(Solar_Day_Energy, 2+3)
works
so I know it’s about Patronus_Day_Energy, which I find strange as it’s in an update rule for Patronus_Day_Energy
And I see that that number is not null.
If that is an Item, it is most likely its state you are interested in. Patronus_Day_Energy.state
But note that itself is a state object; even if that is a Number type Item, it is not exactly a number. You may need to cast it to do arithmetic with it. (Patronus_Day_Energy.state as Number)
If it’s a quantity type (with units) or its a string type, there will be more work to do.
It’s your Item. How did you define it? Number is a number type.
But Number:Temperature for example is a quantity type - you cannot add 3, but you could add 3 degrees.
Okay, so you have apples and oranges to work with.
I’m not that familiar with doing maths with Quantity Types.
Ideally, you’d work with the QuantityType - it auto deals with units, so whether you start out with 2kW or 2000W and add 50W, the end result is the “same”.
So, if you have the number 3, but you know that represents 3kW, can you load it into a QuantityType variable?
I think this may be as simple as
var myEnergyVariable = new QuantityType (myNumberVariable | “kW”)