That’s your problem. You are telling Rules DSL that it’s a Number, not a QuantityType. So when you do the calculation Rules DSL converts the result to a Number.
It’s yet another reason why forcing the type of variables in Rules DSL is not a good idea. Strange things happen when you do that.
So it works better if you don’t force it.
Also, you’ve defined it as a val which means it’s a constant. You can’t reassign it later. You need to use var.
This crappy type system is one of the many reasons I recommend against doing new development of rules using Rules DSL. Any of the other options are going to be just as easy to code in but avoid all the spooky magic that Rules DSL introduces with it’s pseudo-typeless system which only works part of the time.
In JS Scripting the code above would be:
var SolarProd = items.SE_day_production.persistence.sumSince("2020-05-16T00:00:00").quantityState;
console.info(SolarProd);
SolarProd = SolarProd.add(Quantity("30.1 kWh");
console.info(SolarProd);
There are three examples in my reply in three separate rules languages. The first is Rules DSL. The second is JS Scripting and the third is Blockly. JS Scripting and Blockly require the JS Scripting add-on to be installed and both have a significantly different syntax from Rules DSL (they don’t go in .rules files for one).