Smartthings: possible refresh solution?

General Discussion

Smartthings: possible refresh solution?

Postby R305 » Sat Jan 21, 2017 1:51 pm

Hey Kevin & Scott,

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
R305
newt
newt
 
Posts: 14
Joined: Thu Dec 22, 2016 10:02 am

Re: Smartthings: possible refresh solution?

Postby R305 » Thu Jan 26, 2017 10:44 am

Minor Update:

This modified code has been running for almost a week now and seems to be stable. I have also increased the refresh rate from every 10 seconds to every 5 seconds, with no detrimental effects I can see. It now approximates the responsiveness of my other Zigbee and Zwave devices connected to the Smartthings hub.

So, I think it works - the 1 minute lag may be gone. But before declaring victory, I would love to hear from Kevin and/or Scott about whether or not he thinks this mucks up something else. Thoughts please?

Rob
R305
newt
newt
 
Posts: 14
Joined: Thu Dec 22, 2016 10:02 am

Re: Smartthings: possible refresh solution?

Postby kevin » Thu Jan 26, 2017 11:05 am

Hey if it's working better and it's not interfering with anything then I'd say it's a win. If you want to submit a Pull Request we can merge your changes into the project.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: Smartthings: possible refresh solution?

Postby R305 » Mon Jan 30, 2017 4:53 pm

OK Kevin, will do. Might take a little while longer though since I would hate to pass on any real problems it might have. I've made a few tweaks for stability so far to that end.

Keep up the good work. I'm a fan of this device!

Rob
R305
newt
newt
 
Posts: 14
Joined: Thu Dec 22, 2016 10:02 am

Re: Smartthings: possible refresh solution?

Postby ratty » Fri Mar 03, 2017 12:14 pm

How is this refresh change going, will it be added to the alarmdecoder-smartthings gihub repository?

Kevin, are you planning on adding a alarmdecoder : VirtualMotionSensor device handler to go with the alarmdecoder : VirtualContactSensor you have in now?
ratty
newt
newt
 
Posts: 9
Joined: Fri Feb 03, 2017 3:48 pm

Re: Smartthings: possible refresh solution?

Postby kevin » Fri Mar 03, 2017 12:29 pm

I'm not planning for anything - that is a question for Scott - all of this is greek to me :)
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: Smartthings: possible refresh solution?

Postby ratty » Mon Mar 06, 2017 6:52 am

kevin wrote:I'm not planning for anything - that is a question for Scott - all of this is greek to me :)


Greek or geek? :lol:
ratty
newt
newt
 
Posts: 9
Joined: Fri Feb 03, 2017 3:48 pm

Re: Smartthings: possible refresh solution?

Postby R305 » Thu Mar 23, 2017 1:38 pm

Yeah, so....

R305 wrote:Might take a little while longer though since I would hate to pass on any real problems it might have.


Turns out my update is in directly conflict with one of SmartThings' coding guidelines about chaining multiple runIn() commands. It's literally right in the code reference (DOH). Am working on a better solution that will be more stable and hopefully worthy of distributing. Apologies for whipping out the code above before thoroughly checking it.

Hopefully more to come on this.

Rob
R305
newt
newt
 
Posts: 14
Joined: Thu Dec 22, 2016 10:02 am

Re: Smartthings: possible refresh solution?

Postby kevin » Thu Apr 20, 2017 9:58 am

We should have a release this week that addresses this refresh issue as well as some other issues. Along with smart home monitor integration.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: Smartthings: possible refresh solution?

Postby kevin » Thu Apr 20, 2017 2:43 pm

New webapp and smartthings are released - the refresh issue is gone (new setup instructions) and there is smart home monitor integration.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Next

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests

cron