Array of type switch

  • Platform information:
    • Hardware: Raspberry Pi 2
    • openHAB version: Openhabian 2.1

I need some advice:

I am trying to create an interface that will be able to control up to 256*9 individual light switches. I am communicating via TCP/IP to a lighting controller to do so. Sometimes switch presses on the openHAB web interface will change the state of the switch. Sometimes the lighting controller will get a physical press, and communicate with the openHAB programming. I have already gotten the communication working between the controller and my openHAB interface, so I can control the lighting controller, and I can get information from physical presses as well.

However, now I need to start programming each individual switch, which leads me to the following question:

Is there any way to create an array of type switch?

Something like:

Switch[][] keypadlightarray “Keypad Light Array” = new switch [256][9]

I figure that would certainly be a lot easier than defining about 2500 variables in my openHAB configuration, because the lighting controller communicates with openHAB by giving me a keypad number (0-255) and switch number (9 bit binary)

Or if someone else has any bright ideas otherwise, I am open as well. I am a bit of a noob…


Not directly. The Rules DSL does not support arrays.

It does support HashMaps and ArrayLists which might be useful.

But in a case like this I would recommend using Groups, Design Pattern: Associated Items, and Design Pattern: Working with Groups in Rules.

For example, if your Items are represented by a number you can send a command to that Item using something like:

sendCommand("LightSwitch_"+number, "ON")

To get a reference to that Switch Item you can use:

val lightSwitch = MyLights.members.findFirst[s | = "LightSwitch_"+number] as SwitchItem

tl;dr, use Groups as your arrays.