Arrays in Openhab 1.8.3

Hello guys,
I need to store in an array values from several Numerical items. I have searched in the Forum and the Net but got no luck. What I have in the moment and dont work is

Rules
"
val double[] arrayEnviroment = newArrayList(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)

arrayEnviroment.add(0,(LivingRoom.state as DecimalType).doubleValue) //home_Temp
"

I get an error saying thet I cannot add NULL values…

Can you help me?
Thanks

The Rules DSL doesn’t support arrays.

You can use

List<Number> arrayEnvironment = newArrayList

And then a System started rule to populate it. However, in my experience constructs like these tend to be a code angel and the usually is a better approach.

Some thoughts include:

  • Store the Numbers in Items and use Group as the “array”. See:

HashMaps often come in handy.

We are not writing code that needs to be wholly generic and shared with lots of people. Sometimes just hard coding numerical values like this in a switch statement is far simpler and just more clear than trying to do things the “right” way.