Background:
I have an AD2Pi and a SmartThings hub, and have been having a problem where the alarm status in Smartthings does not update when we come home and disarm. So my smartthings actions that key off of the alarm disarming do not trigger. I would have to go into the Alarmdecoder item and hit "Refresh" for it to change to disarmed. Then things would trigger. Then I noticed in the "recent events" log that after install it was getting a refresh command every 1 minute. I found this in the groovy code that you setup with a cron command. For some reason (I still don't know why) after the first arm/disarm cycle, the cron schedule got removed. That part of the code doesn't get called again to establish the cron schedule. So that's where the update problem seems to have come from.
Possible Solution:
So I was hacking around trying to get the cron to be called if for some reason it was cancelled. Reading about it, it has a 1 minute limit on how often the function is called. So, to solve the update issue I also stumbled on a way to refresh it faster than every 1 minute. Instead of using the recurring scheduling system of cron, I decided to chain together a runIn() schedule at the end of every update. With runIn() you can schedule function calls as soon as 1 second in the future. So right now I have it updating / refreshing every 10 seconds. The clock in Smartthings is not super steady in the 1 second range, so I don't want the calls to overlap.
Here are the groovy code edits I made to the AlarmDecoder (Service Manager) Smart app. Seems stable after about a day of use. Can you tell me if you think this creates any new problems?
(Note: this is not the whole code, just the parts I edited)
In the 'Initialize()' function call refreshHandler() instead of scheduleRefresh():
- Code: Select all
/* commented out for runIn()
scheduleRefresh()
*/
refreshHandler()
Commented out 'scheduleRefresh()' completely
- Code: Select all
/* commented out for runIn()
def scheduleRefresh() {
def minutes = 1
def cron = "0 0/${minutes} * * * ?"
schedule(cron, refreshHandler)
}
*/
Added the runIn() command (set to 10 seconds) at the end of 'refresh_alarmdecoders()'
- Code: Select all
def refresh_alarmdecoders() {
log.trace("refresh_alarmdecoders-")
getAllChildDevices().each { device ->
// Only refresh the main device.
if (!device.deviceNetworkId.contains(":switch"))
{
log.trace("refresh_alarmdecoders: ${device}")
device.refresh()
}
}
runIn(10,refreshHandler) // Just added
}
Thoughts and/or criticisms?
Rob