So, I have a SmartApp that I am working on. In this app, the user selects a set of switches to monitor for events. When one of these switches is activated, the app performs an action at that same switch. The problem I am having is how do I perform an action on a single switch and not all of the switches?
Here is my code so far:
preferences {
section("When any of these switches is toggled...") {
input "switches", "capability.switchLevel", title: "Which Switch", multiple: true
}
section( "Notifications" ) {
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes", "No"]], required: false
input "phoneNumber", "phone", title: "Send a text message?", required: false
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribe(switches, "switch", switchHandler, [filterEvents: false])
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribe(switches, "switch", switchHandler, [filterEvents: false])
}
def switchHandler(evt) {
def toggledSwitch = switches.findAll{it.id == evt.deviceId}
def recentStates2 = toggledSwitch.eventsSince(new Date(now() - 30000), [all:true, max: 200])
}
This seems to work except I am getting the following error when searching for events:
c4bf7f95-9ce4-4b23-a1d2-b4b0411beb81 12:35:26 PM: error groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.eventsSince() is applicable for argument types: (java.util.Date, java.util.LinkedHashMap) values: [Mon Jun 30 18:34:56 UTC 2014, [all:true, …]] @ line 54
I believe because toggledSwitch is an ArrayList and the method I am using (eventsSince) is intended for a single device.
Is there any way to convert it to a single device or is there a better way of accomplishing this?