So where does the POST fit into this? Is that how you want to send something from Hubitat to your custom mobile app (not to be confused with the custom Hubitat app/automation)? If so, this is basically a virtual notification driver:
metadata {
definition (name: "Virtual Notification Device"", namespace: "RMoRobert", author: "Robert Morris") {
capability "Notification"
}
preferences {
input(name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true)
input(name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true)
}
}
void installed() {
log.debug "installed()"
initialize()
}
void updated() {
log.debug "updated()"
initialize()
}
void initialize() {
log.debug "initialize()"
Integer disableTime = 1800
if (logEnable) {
log.debug "Debug logging will be automatically disabled in ${disableTime} seconds"
runIn(disableTime, "debugOff")
}
}
void debugOff() {
log.warn "Disabling debug logging"
device.updateSetting("logEnable", [value:"false", type:"bool"])
}
void deviceNotification(notificationText) {
if (logEnable) log.debug "deviceNotification(notificationText = ${notificationText})"
sendEvent(name: "deviceNotification", value: notificationText, isStateChange: true)
}
But then what you'll need to do is actually implement the deviceNotify()
command in way that really does something, which in your case sounds like sending an HTTP POST. For that, I'd recommend Hubitat's asynchttpPost()
method, something like:
Map params = [
uri: "http://myIPAddress",
contentType: "application/json", // or whatever
path: "/myPath",
body: [notificationText: notificationText], // this will get converted to a JSON
timeout: 15
]
asynchttpPost("myAsynchttpHandler", params)
which you would need to couple with another "callback" method like:
void myAsynchttpHandler(resp, data) {
if (logEnable) log.debug "HTTP ${resp.status}"
// whatever you might need to do here (check for errors, etc.),
if (logEnable) log.debug "HTTP ${resp.body}"
}
The Hubitat docs have more on this (and other) methods, though Community posts will probably be even more helpful: Common Methods Object - Hubitat Documentation
Maybe this will help?