idealerror
(Idealerror)
December 11, 2016, 9:37pm
1
Hey guys,
What’s the best practices for polling devices? I’m trying to poll a device every few minutes to check the status. The device is an HTTP API.
Right now I’m just testing with:
def initialize(){
log.debug "Initializing.."
def freq = 1
schedule("0 0/1 * * * ?", poll)
}
def poll()
{
log.debug "Polling.."
getStatus()
}
getStatus() will go out and fetch via HTTP the status of a device. The problem is, nothing is polling right now. I’ve been watching the logs waiting for “Polling…” but nothing shows up.
idealerror
(Idealerror)
December 13, 2016, 12:11am
3
Well, that not my issue.
My issue is the device is not being polled AT ALL. ST says it should be every 10 minutes, this is definitely not happening.
geko
(Geko)
December 13, 2016, 12:30am
4
Polling was newer reliable. I think they’ve stopped doing that long time ago. See the Pollster thread.
Please note that excessive polling of some devices (particularly Zigbee and Z-Wave) may cause network congestion and lead to degraded system performance. Therefore, polling rate faster than 5 minutes is not recommended. The author of this software bears no responsibility for your system performance. Use it at your own risk.
I don’t claim originality of the idea, but I needed one badly for some of my projects and didn’t find anything among the shared apps. So there it is…
Many SmartThings devices rely on polling to periodically update their status. These devices have ‘polling’ capability and provide poll() function that the SmartThings polling engine calls approximately once every 10 minutes. Unfortunately, SmartThings polling engine proved to be unreliable and sometimes it stops working…
idealerror
(Idealerror)
December 13, 2016, 12:33am
5
@geko
Hmm, so if I have a custom switch type that runs off an HTTP API. There’s no way to have ST automatically go out and check if it’s on or off? Unfortunately I cannot have the switch update ST so I have to rely on ST to reach out and touch the switch itself.
Ideas?
geko
(Geko)
December 13, 2016, 12:36am
6
No, that’s not how things work. ST does not poll switches. Your switch has to send an event when it’s state is changed. So you’ll need to send an event in your http handler. No polling is necessary.
idealerror
(Idealerror)
December 13, 2016, 12:54am
7
Ouch.
Insteon would never support that in a million years.
I’ll work around it I guess.
geko
(Geko)
December 13, 2016, 3:11am
8
That’s what Pollster is for.
jjslegacy
(Jeffrey)
December 13, 2016, 3:17am
9
Which insteon controller are you running? ISY or?
idealerror
(Idealerror)
December 13, 2016, 5:02am
10
Hub 2422
I’ve already built all the device types for all my devices but cannot poll if it turns on or off at the switch.
Edit: I can poll it but ST doesn’t poll it automatically like it should.
bago
(John)
December 13, 2016, 12:45pm
11
I think this was a design choice. ST is event driven in that respect. Pollster, as mentioned, was a solution for your use case.
jjslegacy
(Jeffrey)
December 13, 2016, 5:14pm
12
Yeah that’s never going to work or be reliable. I use a mix of Pollster rest API call and google apps scripts to make the request every few minutes. Works perfectly and I don’t have to rely on smartthings for any scheduling.
I have an ISY so a bit different but same concepts needed.
geko
(Geko)
December 13, 2016, 9:02pm
13
Rumor has it, that device handlers can now call runIn()
to schedule callback execution. If that’s the case, you can create self-polling devices.
idealerror
(Idealerror)
December 13, 2016, 11:59pm
14
Lightbulb!
Adding a runIn() to poll() forces it into a loop.
We have liftoff.
1 Like
geko
(Geko)
December 14, 2016, 12:02am
15
Just tried it myself. schedule()
works as well. Awesome!