I realize this a silly question and relates to Groovy vs. ST but I’m at wits end. How does one interact with what I’m guessing are arrays of strings created when you have a SmartApp that has a preference that includes multiple sensors, modes, etc? For example, I’m trying to put together an app that will do something if the location is in a certain mode, but not in others.
To start with, I’ll settle with just flipping through the modes that would qualify. Here’s the code:
@Mike_Maxwell - I get a “ava.lang.IllegalArgumentException: Property ‘inspect’ is not supported for devices” when I try that. I’m trying to write an app that needs to know the on/off contition of a siren and once again I’m feeling in the dark. I have no idea how I can figure out what .currentState .sirenState, .whoTheHeckKnows goes after the device name.
I read through the documentation linked to (very helpfully) by @copyninja and that suggests that I would use: alarm.currentValue(“switch”) to reach those values. But this:
log.debug “Current Alarm State is: $alarm.currentValue(“switch”)”
very unsurprisingly throws out a million errors (I doubt it handles nested " very well. So I’m back to feeling int the dark on how to resolve that. I know there is a way. . .but I have no idea how.
So here are the capabilities: https://graph.api.smartthings.com/ide/doc/capabilities
You will be looking for mySelectedAlarmDevice.currentValue(“alarm”) == “off”, make sense?
See how the possible attribute values are listed by device type?
If you have multiple alarm devices, then you will need to check the state of each one in a loop
Thanks @Mike_Maxwell! I’ll read through that documentation, and thank you very much for that link. To your prediction I am indeed looping through multiple devices, or at least building the app to support that. Here’s the function, which is intended to be used to change modes if a very specific set of motions/events occur, but NOT if a security alarm is actually going off.
private CheckForAlarms() {
log.debug “Entering CheckForAlarms”
def n = 0;
def found = false;
alarm.each {
def alarmState = alarm[n].currentValue(“switch”)
log.debug “Current state for alarm $n is: $alarmState”
n++
if (alarmState == “on”) {
log.debug “I found an alarm going off, refusing to disable it…”
found = true
return found
}
}
log.debug “I found no triggered alarms…”
return found
}
This function feels highly inefficient to me, but I can understand the simple syntax. So it’s working for me!!