@watou.
I never understood those class definition.
So using String
"WTH_CommonId.state.toString" is working nicely.
but if the item is a Number, then
var Number test
test = test_number_item.state.toNumber
is failing.
so I have to use the
test = test_number_item.state as DecimalType .
Also"test = test_dataetime_item.state.DateTime" is failing so I have to use some other construct I cannot remember right now.
All those type conversion are not following a similar pattern.
I never understood why this makes sense.
Do know about a deeper logic why this is so convoluted or is this just “historical” reasons and it was never properly fixed?
The reason .toString works is because the rule language is built on top of Java, and every object in Java has a .toString() method. (In the rule language, you can drop empty parentheses.) There aren’t equivalent methods like .toNumber(). In openHAB, every different kind of item state is of some XXXType class. If you know an item’s state is a number, then it must be of the DecimalType class, but the rule language needs to be told you want to treat it like a number by saying something like var Number myNumber = myItem.state as DecimalType.
You could have
var DateTimeType myDateTime = test_dataetime_item.state as DateTimeType
var Calendar cal = myDateTime.calendar
but it would help to know the Java Calendar class.
It would be very helpful to have more documentation about these things.