Http Post Notification Device

Hi
I would like to send notifications using an http request and would like to have an actual notification device to do it.

Has anyone created one I can use?

What is an "actual notification device"? And welcome to Hubitat.

To clarify, are you looking to receive an HTTP POST on Hubitat and then "convert" that into a notification you can actually send to a device? If so, I don't know of any built-in way to do exactly this or anyone who has written a community driver that can, but I'm thinking you would really need an app (to respond to a specified HTTP POST endpoint), and then that app would in turn send the notification your "real" notification device on Hubitat (via normal device commands); I don't believe the former is something best suited for a driver, though there are also ways to receive unsolicited HTTP there (but no way without an app to "tie" it to another device, unless you also write whatever does the "real" notification to your "real" device into that driver too, effectively also writing a driver for whatever that is).

Well if this is the case as to what OP wants, it can be done in Webcore. I use a lot of HTTP requests, mostly communicating between my PC's and Hubitat. I use Hubitat to monitor when my PC's are turned on and off, and set a virtual switch accordingly. Though, it would be very easy to send a push notification when a HTTP request is received.

You can pick a text notification and it give you a list of devices, I wanted to create a device so I can send a notification using ifttt.

I could use pushover for it but I don't want to pay for multiple devices.

That could be done in Rule Machine, too, with a cloud endpoint (except I think those are just GETs) if you have "predetermined" notification content; my assumption was that they wanted arbitrary content in the body of a POST, with that being the notification text. I think the above points to this being the case, but I'm still not sure exactly how it would be supposed to work. :slight_smile:

2 Likes

FYI, you don't have to pay for multiple devices with Pushover.

Still not clear to me why you just don't use the Hubitat mobile app for notifications. Why go through IFTTT?

1 Like

I don't like the app so I am writing a basic android app for the dashboard, I want a dark theme and I am learning Flutter at the moment so I figure why not make one.

I have found a driver for pushover I will modify that that to get it to send http requests, It doesn't look too hard.

I am going to write a custom add to get the notifications.

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?

1 Like

That is perfect thanks

Well not sure with Rule Machine, but with Webcore this can be done as well. You can set variables based on arguments in the HTTP Request. Just set a variable for your text and pass that thru as a notification.

I have this setup as well. I send notifications from Hubitat to my PC's. I then use a program called Eventghost which hosts a webserver to receive them. I have a piston setup that sends notifications from Hubitat to the PC which displays the notification on screen for a few seconds. Its nice when I'm on the computer and it pops up saying the washer/dryer is done, etc...

1 Like

I used the sample cord that was provided and created IFTTT maker api device enjoy.

hubitat/ifttt-notification.groovy at master · korich/hubitat (github.com)

anyone know how to pass a notification to this from maker api?

Which of the multiple attempts in the three-year-old posts above are "this"?

Regardless, if there is a driver with a command, you can just run the command (and pass any needed parameters, should there be any) using the standard MakerAPI format.

EDIT: Nevermind, I see this was addressed in a duplicate post: How to call a device notification object from makerapi

2 Likes

thanks posted the other one because exactly that reason.. this was so old not sure anyone would read it...