I am hoping someone can help me with a Groovy syntax question. I am sure its something silly, but I am not able to figure out how to fix an error I am getting:
groovy.lang.MissingMethodException: No signature of method: java.lang.String.active() is applicable for argument types: () values: []
I have my alarm panel integrated with SmartThings via AD2Pi and I want my alarm motions to show up like my zwave motions showing activity. I have 3 motions and so I created 3 virtual devices so now I am working on a SmartApp to update the state of these virtual devices when the alarm reports activity. If there is a way to do this in the alarm device code that doesn’t require a SmartApp, even better but I don’t know how to do that. I am new to virtual devices and how they work.
The reason I am getting this error is I am trying to dynamically specify the device in the code based on the event name using a variable. I know I could create a case statement or several If statements to hardcode the device name, but I am sure there is a way to dynamically specify that Xmotion.active(). My alarm has 20 zones so after getting the motions to work, I plan to create virtual devices for the others as well and thus want to simplify my code. This is where I am hoping someone can help me.
Code:
preferences {
section("Which Alarm?") {
input "alarm", "capability.alarm", multiple: false, required: true
}
section("Kitchen Motion"){
input "kitchenMotion", "capability.motionSensor", multiple: false, required: false
}
section("Foyer Motion"){
input "foyerMotion", "capability.motionSensor", multiple: false, required: false
}
section("Upstairs Motion"){
input "upstairsMotion", "capability.motionSensor", multiple: false, required: false
}
}
def installed() {
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
subscribe(alarm, "kitchenMotion", motionHandler)
subscribe(alarm, "foyerMotion", motionHandler)
subscribe(alarm, "upstairsMotion", motionHandler)
}
def motionHandler(evt) {
def deviceName = evt.name
def deviceValue = evt.value
log.debug "deviceName: ${deviceName}, deviceValue: ${deviceValue}"
if (evt.value == "active") {
("${deviceName}").active()
//"${deviceName}".active()
//("${deviceName}.active()")
} else {
("${deviceName}").inactive()
//"${deviceName}".inactive()
//("${deviceName}.inactive()")
}
}
You can see I tried many different things like putting () around the deviceName variable in different places, but none of these work. The log.debug statement confirms that ${deviceName} is “kitchenMotion” for example so not sure why I cannot transpose that variable and make it execute “kitchenMotion.active()”.
Thanks in advance!