Hi all,
@rossko57 gave some great examples of working with QuantityTypes that hold Units of Measurement in DSL rules, i.e. here.
One crucial item is missing however, and I have not been able to figure out how to get it to work. How do I use the state of a QuantityType Item in a DSL variable and work with it?
I have an item that is set up as a “Number:Volume” number type item using m³ as the unit.
I am simply trying to copy it into a variable at the start of my rule and perform some manipulations:
var BWZ = BWZ_Zaehlerstand.state
I would assume that BWZ now hold the state of my item with the unit attached.
I.e. If I do (as in Rossko’s examples)
val BWZ = 33|"m³
My call above should do the same, right (assuming the item’s state is 33 m³)?
And if I now have a second Number:Volume item, that I cast into the variable “Offset”, this should work too:
var Jahr = BWZ - Offset
However, the actual code gives me error messages and the rule won’t work:
[internal.handler.ScriptActionHandler] - Script execution of rule with UID 'bewaesserung-2' failed: Unknown variable or command '-'; line 92, column 20, length 46 in bewaesserung
What still works is to get rid of the units in variables by casting them like so:
var Double BWZ = (BWZ_Zaehlerstand.state as QuantityType<Number>).doubleValue
and simply work without the units in the rest of the code.
However at the end of my rule i then do sendCommands to any updated items without the units attached which is probably not going to be supported in future versions, which got me started on wanting to work properly with the units.
Any idea what I am doing wrong?
Best,
Thomas