Hi,
I hacked some code together which allows ST to update switches in my Vera automation system depending on availability of presence FOB’s.
The code works but the problem I have that once in a while the GET request is not answered (not sure if it a ST problem or a Vera problem).
So what I would like to do is have ST check whether a reply following the GET was received and resend the command in case it was not.
Below is code I’m using and the following is the reply that I would get from Vera is the same command was executed via the web browser:
Vera reply:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<u:SetTargetResponse xmlns:u=“urn:schemas-upnp-org:service:SwitchPower:1”>
OK
</u:SetTargetResponse>
Code:
preferences {
section("When a presence sensor arrives or departs this location..") {
input "presence", "capability.presenceSensor", title: "Which sensor?"
}
section("Set Vera DeviceID...") {
input "VeraID1", "number", title: "DeviceID"
}
}
def installed() {
subscribe(presence, "presence", presenceHandler)
}
def updated() {
unsubscribe()
subscribe(presence, "presence", presenceHandler)
}
def presenceHandler(evt) {
def deviceNetworkId = "0A0A000A:D98" // "10.10.0.10:3480" update with your Vera IP in hex format
def ip = "10.10.0.10:3480" // This is the ip and port of the Vera in the network
if (evt.value == "present") {
log.debug "${presence.label ?: presence.name} has arrived at the ${location}"
sendHubCommand(new physicalgraph.device.HubAction("""GET /data_request?id=lu_action&DeviceNum=${VeraID1}&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))
sendPush("${presence.label ?: presence.name} has arrived at the ${location}")
} else if (evt.value == "not present") {
log.debug "${presence.label ?: presence.name} has left the ${location}"
sendHubCommand(new physicalgraph.device.HubAction("""GET /data_request?id=lu_action&DeviceNum=${VeraID1}&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0 HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))
sendPush("${presence.label ?: presence.name} has left the ${location}")
}
}
Can anyone advice how I could get this feedback loop closed?
Thanks !