Help Needed: sendCommand not working with arrayList of String

Hey guys,

I’m working on a rule that reads the state of my Elk/NESS home alarm state over serial and updates the state of a switch item.

I’ve run in to some issues when trying to set the state of my alarm Items from my rule.
The documentation of the sendCommand function says that it takes two strings as inputs but I can’t seem to pass a string to this function without it throwing an error. Here is my code that isn’t working:

alarm.items

Switch Alarm_PIR_GF_Lounge "Lounge"
Switch Alarm_PIR_GF_Stairs "Down Stairs"
Switch Alarm_PIR_FF_Stairs "Up Stairs"
Switch Alarm_PIR_FF_MasterBedroom "Master Bedroom"

alarm.rules

val ZoneArray = newArrayList("0","1","2","3","4","5","6","Alarm_PIR_GF_Lounge", "Alarm_PIR_GF_Stairs", "9", "10", "11", "12", "13", "14")

switch zoneStatus {
    case zoneStatus == ZoneStatusTable_NormalOpen : sendCommand(ZoneArray.get(zoneNumber).toString, OFF)
    case zoneStatus == ZoneStatusTable_NormalEOL : sendCommand(ZoneArray.get(zoneNumber).toString, OFF)
    case zoneStatus == ZoneStatusTable_ViolatedOpen : sendCommand(ZoneArray.get(zoneNumber).toString, ON)
  }

The above does not work, I get the error:

Rule ‘Interpret Alarm Command’: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

The below does work which is confusing because the documentation says that all I need to pass the sendCommand function is the string that matches the item name.

switch zoneStatus {
    case zoneStatus == ZoneStatusTable_NormalOpen : sendCommand(Alarm_PIR_GF_Lounge, OFF)
    case zoneStatus == ZoneStatusTable_NormalEOL : sendCommand(Alarm_PIR_GF_Lounge, OFF)
    case zoneStatus == ZoneStatusTable_ViolatedOpen : sendCommand(Alarm_PIR_GF_Lounge, ON)
  }

Any help or thoughts would be much appreciated.
Thanks

I’d start by breaking it down into steps. Do the array get, show the expected string with logInfo and see if it is what you expect.

There is a completely different approach to this kind of requirement based on OH Groups
Example shows how to work through the Items in a Group

Thanks for the tip. I have confirmed that the array get is working as expected, however I’m confused at why the code below does not work:

sendCommand("Alarm_PIR_GF_Lounge", OFF)

I get the same error as I did before:
Rule ‘Interpret Alarm Command’: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(java.lang.String,java.lang.String) on instance: null

I’ll take a look at the alternate method of getting the job done without using arrays, thanks for the suggestion