I’m having a bear of a time getting a (what i thought) was a 1-2 second delay on a device handler
background:
raspberry pi zero w
2 port relay, of which one port is connected to garage door trigger
WEBIOPi for the REST api calls
device handler calls /gpio/port/on then callback issues /gpio/port/off
it’s that on/off that’s killing me. it fires off almost instantly and the garage door needs something like 1-2 seconds of “on” to register the click. sometimes it fires but more often than not i’m repeatedly pressing my trigger to make it work.
my code is horrible, i’m not even going to try to say it’s good. what am i missing for introducing this delay?
preferences {
section("Internal Access"){
input "internal_ip", "text", title: "Internal IP", required: false
input "internal_port", "text", title: "Internal Port (probably 8000)", required: false
input "internal_on_path", "text", title: "Internal Path (/GPIO/number/)", required: false
}
}
metadata {
definition (name: "URI Switch", namespace: "athlonduke", author: "me") {
capability "Switch"
}
// simulator metadata
simulator {
}
// UI tile definitions
tiles {
standardTile("toggleButton", "device.button", width: 2, height: 2, canChangeIcon: true) {
state "default", label: 'Toggle', action: "switch.on", icon: "st.Transportation.transportation12", backgroundColor: "#bbff21"
}
main "toggleButton"
details (["toggleButton"])
}
}
def parse(String description) {
//log.debug "i'm over there"
//log.debug(description)
}
def parse(physicalgraph.device.HubResponse hubResponse){
//log.debug "in parse: ${hubResponse.body}"
runIn(2,reallyTurnOff())
}
def on() {
log.debug "Sending pulse"
reallyTurnOn()
}
def reallyTurnOn(){
def port=port()
def result = new physicalgraph.device.HubAction(
method: "POST",
path: "${internal_on_path}function/out",
headers: [
HOST: "${internal_ip}:${port}"
],null,
[callback: parse]
)
[
sendHubCommand(result),
"delay 1000"
]
//sendEvent(name: "switch", value: "on")
log.debug result
}
def reallyTurnOff(){
def port=port()
def result2 = new physicalgraph.device.HubAction(
method: "POST",
path: "${internal_on_path}function/in",
headers: [
HOST: "${internal_ip}:${port}"
]
)
[
sendHubCommand(result2),
"delay 1000"
]
//sendEvent(name: "switch", value: "off")
log.debug result2
}
def port() {
def port=80
if (internal_port){
port = "${internal_port}"
}
return port
}