Argh - ninja'd by @thebearmay's mad tech skillz.. Oh well - here is my take on the same thing. I adapted @bertabcd1234's driver and am using "post". I haven't done this in a while so am a bit rusty.
In HE:
- copy and paste the driver below into a new driver that can be added in the "Drivers Code" section of the HE Nav menu.
- Create a virtual device and select "virtual notification (user)" as the driver.
- Configure the new device like this... subbing [node-red] for actual address
Then in Node-RED using an "http-in" node do something like this:
You can test in HE by typing in some text in the "Device Notification" box and clicking the title part (it's actually a button).
Results should show up in the msg.payload along with some other properties you can ignore.
HE custom driver - Virtual Notification Device for Node-RED
metadata {
definition (name: "Virtual Notification Device", namespace: "RMoRobert", author: "Robert Morris") {
capability "Notification"
capability "Actuator"
}
preferences {
input( name: "nodeRedAddr",type:"string",title: "Node-RED server address", description:"The location of the Node-RED server including port #.", defaultValue:"http://[Node-RED ip address]:[port]")
input( name: "nodeRedPath",type:"string",title: "Node-RED path", description:"", defaultValue:"/notify")
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 deviceNotify() {
}
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}"
}
void deviceNotification(notificationText) {
if (logEnable) log.debug "deviceNotification(notificationText = ${notificationText})"
sendEvent(name: "deviceNotification", value: notificationText, isStateChange: true)
Map params = [
uri: nodeRedAddr,
contentType: "application/json", // or whatever
path: nodeRedPath,
body: [notificationText: notificationText], // this will get converted to a JSON
timeout: 15
]
asynchttpPost("myAsynchttpHandler", params)
}