How does app get latest about devices


(MJ) #1

Hello,

Another nube question. I’ve got my device type running, i can turn on, off lights. i can dim my lights, i can refresh the status. So when the smartthings app comes up, how does it get the current status of my devices? is there something i need to put in devicetype to handle that? if i manually turn off the lights, or use the insteon app to turn on or off the lights, outside of the smartthings app, how when i bring up the ST app can i refresh the things with the latest info without having to hit the refresh button?

Michael.


(sidjohn1) #2

the command in your devicetype that you are looking for is poll()


(MJ) #3

thanks sidjohn1. i’ve got the capability “Polling” and the def poll() and the poll() routine is not being called. in my example, i can’t use parse() because i am talking to a hub which in turn talks to the device. so the deviceID column isn’t the actual device i am talking to. i was told that parse() is only called for defined devices (by deviceID column) Do you know if that is the case for poll()?

https://gist.github.com/impactmrj

-michael.


(sidjohn1) #4

Ok, now I see what you are really asking. I have a devicetype that uses hubaction. In the headers I call a delay and refresh or poll of the device so the data is always in sync. The same concept may work for httpget.

    	try {
		hubAction = [new physicalgraph.device.HubAction(
		method: "GET",
		path: rooPath,
		headers: [HOST: "${ip}:80", Accept: "application/json"]
    	), delayAction(10000), api('refresh')]
    }

https://github.com/sidjohn1/smartthings/blob/master/ThinkingCleaner.groovy


(MJ) #5

when i control the lights using the smartthings app, everything works perfectly. what happens if i turn off the light manually? or using the insteon app? when i go into the smartthings app, the device status is out of date, stale. if the poll() isn’t being called, how can the device tiles/state/etc get updated?


(sidjohn1) #6

for that situation there is pollster, it will poll a device every so often and force an update. it’s not elegant but it works. I currently use it on a switch that does not update smartthings if i use the physical buttons, i poll it every minuet. If you want it more frequently you can write a smart app that polls as often as smartthings servers will let you :wink:
https://github.com/statusbits/smartthings/tree/master/Pollster