Polling is an important feature as far as SmartThings and Custom Device Types are concerned. I think it needs some immediate attention from SmartThings team.
@krvarma, I wrote my first custom device and was having exactly the same problem as you. I had to write the app that @florianz suggested. It’s a bit of a hack but has been working great for a couple of days now.
runIn didn’t work for because it’s not supported in the Device class.
Poll is a bit funky. It was built only as a device heartbeat to ensure its status on the network. It will stop running if there are a lot of events, it will stop if the poll returns nothing, and lots of other use cases that make it stop.
We have discussed adding cron to device types but though it may end up causing a lot of unnecessary network traffic. What we settled on was a Service Manager SmartApp architecture where a SmartApp calls functions on the device type using cron.
It would be good to a have a Poll SmartApp that device type developers can use to test with.
I’m struggling with this myself at this moment. My device type has polling capability which calls a method on Service Manager. This works for a while and then it dies. Now I know why.
It would be great if there was a knowledge base for this type of gotchas.
This is what I’m using. Seems to be working so far.
/**
* Device Poll
*
* Copyright 2014 Steve Herrell
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "Device Poll",
namespace: "steve.herrell@gmail.com",
author: "Steve Herrell",
description: "Poll particular devices to make sure readings are up to date.",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
)
preferences {
section("Devices To Poll") {
input "pollingDevices", "capability.polling", multiple: true, title: "Pollable Devices"
}
section("Polling Interval (defaults to 15 min)") {
input "pollingInterval", "decimal", title: "Number of minutes", required: false
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
doPoll()
}
def updated() {
log.debug "Updated with settings: ${settings}"
doPoll()
}
def doPoll() {
log.debug "running doPoll"
pollingDevices.poll()
def timeOut = (pollingInterval != null && pollingInterval != "") ? pollingInterval : 15
runIn( timeOut * 60, "doPoll",)
}
hey @NickW, sorry I didn’t get time to work on it. Planning to do this week end. I will get back here after implementing it.
RBoy
(www.rboyapps.com - Making SmartThings Easy!)
157
Is there some way to set the default polling frequency for ST platform? I think the standard isabout 15 minutes (1000seconds) but I want to reduce it as it’s draining my batteries.
RBoy
(www.rboyapps.com - Making SmartThings Easy!)
158
@urman can you shed some light on this comment. What do you mean by when a poll returns nothing it still stop?
I recently put a check mechanism in the poll function of the my thermostat device. The check doesn’t always run the zwave updates and basically does nothing (to save battery), Suddenly the polls have stopped coming.
How do I restart the polls?
Also what can I return from a poll function so it doesn’t stop without actually issuing a zwave command?
@RBoy I can’t speak to how it currently works, but how it used to work was if there were no responses from a poll after so many times it would stop polling. No reason to poll for something thats not there.
RBoy
(www.rboyapps.com - Making SmartThings Easy!)
160
@urman by no response do you mean so sendEvents being reported or no return value from the function?
Is there any way to find out what’s the current logic. It’s been days since poll has been called and I can’t figure out how to restart it
That seems like an odd design for a mesh network. The whole point of mesh resilience is that the controller shouldn’t care if an individual device is offline for awhile. It might be undergoing maintenance or being readied for a new location. In commercial installs we tried to limit polling to 5% of total traffic, but once a device was on a polling schedule, we stayed with that schedule as long as the device had a network ID, regardless of any response received.
For home automation, if someone was remodeling and devices were offline even for a couple, of weeks, I wouldn’t have the controller silently shut off polling because of a non response. I’d leave the schedule running as is. If the homeowner wants to change the polling, they can change the schedule. Or exclude the device.
@Ron I remember that you have Aeon Smart Energy Switch (hanging ones) Zwave metering switch. Are they polled ever? I have two of these and they never get polled.
Neither does the newest model (Aeon Labs Aeotec Z-Wave Smart Switch 6, Gen5)
Hues are no longer polled. It gets broken every few days. All of a sudden it works, and the next day goes for a toss.
I wrote a Smart App for the Aeon Smart Energy which checks the power level every X minutes as configured.
I found it wasn’t working two days ago so I had to open the SmartApp and reconfigure.
Basically as this thread indicates ST Scheduled Events and polling is very broken.
They say if they poll a device and it doesn’t return a result they turn off the polling and/or scheduled events because “there is no point polling a device that isn’t there” this assumes the network is perfect and a signal is never dropped. I think that is a mistake. If I ask for a method to be called every 15min I want it called every 15min until I say stop.
Can you imagine if cron was written this way. Well the cron task failed so lets just stop scheduling it…
I can’t really figure out a way to fix this issue. ST needs to provide a reliable task scheduler and/or polling ability.
Here is my Aeon DSC06 Smart App if you want to check it out.