Hi all
Total newbie to smartthings and certainly to writing device types.
I’ve searched and searched but cant find any example of how to create a device type that will listen for network events using hub action. I found the below but not sure if this should be done in a device type or a smart app.
I am essentially trying to integrate smarthings with a raspberry pi which will detect motion and send an event or notify smartthings. I have been able to connect with smartthings to the pi (and parsing the results) but I essentially want the communication the other way around (pi to smarthings)
def someCommand() {
subscribeAction("/pi/motion")
}
private subscribeAction(path, callbackPath="") {
log.debug "subscribe($path, $callbackPath)"
def address = getCallBackAddress() //address of hub
def ip = getHostAddress() //address of device to connect to
def result = new physicalgraph.device.HubAction(
method: "SUBSCRIBE",
path: path,
headers: [
HOST: ip,
CALLBACK: "<http://${address}/notify$callbackPath>",
NT: "upnp:event",
TIMEOUT: "Second-28800"
]
)
log.debug "SUBSCRIBE $path"
return result
}
Many thanks in advance
JJ