Mathematical operations on item.rawState using Javascript keeping UoM

You have to use the methods on the QuantityType to do the math or you need to convert them to the same unit before doing a plain number addition.

var myresult = value1.add(value2);

or

var myresult = value1 + value2.toUnit('kWh');

Though this second approach will still lose the units in myresult. If you want to keep the units you must use the methods to do math with QuantityTypes.

1 Like