Send URL to Pushover?

I would like to include a URL in the message sent to pushover in one my apps (Life360 Tracker) but I just can't figure out how! Sending a message is easy, adding in the URL not so much. :sunglasses:

Could someone give me an example? This is what I use now to send the message...

def pushHandler() {
	if(logEnable) log.debug "In pushNow..."
	theMessage = "${state.theMessage}"
	if(logEnable) log.debug "In pushNow - Sending message: ${theMessage}"
   	sendPushMessage.deviceNotification(theMessage)
	state.msg = ""
}

Thanks!

If you take a look at my old Pushover Driver (before Hubitat added built-in version), you can at least see how the URL functionality was added. There is no way from an App to include a URL within the deviceNotification()'s string that is passed in. The URL and URL Title are user preferences/settings within the driver.

Two options that I can think of...

  1. Ask the Hubitat Team if they would consider adding some sort of additional delimiters that could be used allow the URL and URL Title to included in the deviceNotification() string argument. These would then be parsed out and sent in the http call correctly.

  2. You could try to modify my old driver to add this functionality. Be aware - I haven't used it in a while, so I am not sure whether or not it still works correctly.

1 Like

@bptworld are you an android or apple guy?

Thanks, I took a look at that this morning but didn't get very far... now I know why. :wink:

1000% Android

edit: need to add more zero's to that 1,000,000%, lol

You should check out join. @stephack made an excellent driver and posted great instructions. It may be able to do what you want.

yeah, I've heard about it but was looking for something built in for the masses. Wanted to send a push like...

Emma has arrived at The Park
Map to The Park

Using the lat, and long from Life360 with States. I can make the url easy enough but couldn't figure out a way to send it to Pushover.

Multiplied by 1,000

Well if you are considering making such things available as variables, the way @stephack setup the custom formatting could still make this useful.

oh yeah? Have an example? :thinking:

Well. You can send you message with separators he has defined [cc]and it allows you to manipulate the different options the driver has for creating notifications.

Join allows you to setup numerous different kind of actions that can be ran from an android device.

These actions can be presented as buttons within the notification. Those buttons can be picked based upon the above custom formating.

So for example if I can pass the url into the join api with the custom formatting. I can then react to it any many ways in my android device.

1 Like

I just send the raw URL and select it in Pushover, not pretty but works :wink:

https://maps.google.com/?q={add latitude},{add longitude}

Would be nice to have it more pretty though.

Yeah, I got that too. My OCD won't let that slide :wink:

Playing around with @ogiewon code now. Trying to add some stuff in.

1 Like

@bptworld

Lol while were on the subject. Several of the attributes could be handy if available as variables for messages.

Ha, second request for more variables! Guess i better get on that.

1 Like

@bptworld, I skimmed this thread. Are you trying to pass the URL into the Pushover Supplementary Url input from another app?

If yes, I'll try to whip up something for you in a bit (busy atm). You can look at the deviceNotifications section of Dan's driver where I used [ ] to determine message priority. You can do something similar with the url.

If you want to allow for both custom priority and supplementary url, then you might need to use delimiters like I did in my Join driver. Take a look at the buildMessage() function. Feel free to use whatever part of the code you see fit.

1 Like

Yes! I started working with Dan's driver a little bit ago. Haven't gotten too far with it yet but getting there.

That's actually similar to how I did it with Follow Me.

Thanks!

Just put up a new version... with all attributes as wildcards! :grin:

Thanks for posting this, its enabled me to get messages to my PC at least :+1: Which opens G maps nicely, and looks pretty :wink:

image

1 Like

This isn't too bad using the stock push driver...

1 Like

I wasn't sure exactly how you planned to use this but my assumption was that you only needed to dynamically change the supp url and title with a location url.

With that in mind, here's what I came up with.
You can still use the priority prefixes (L, H, E, etc) but you can also add a [LOC] custom command that will override the default supp url with what follows it. The message will need to be constructed as follows.

[L,H,E]message[LOC]http://locationUrl

I hard-coded the url title to "Location Link" because I assume that's all it will ever be. You can easlily add code to make that an input or whatever you need. Hopefully this is what you needed. Now back to back breaking work...and thanks for the excuse to rest :wink:

Replace the deviceNotifications() method with this one. I commented my changes so you can see them in the code.

def deviceNotification(message) {
    if(message.startsWith("[L]")){ 
        customPriority = "-1"
        message = message.minus("[L]")
    }
    if(message.startsWith("[N]")){ 
        customPriority = "0"
        message = message.minus("[N]")
    }
    if(message.startsWith("[H]")){
        customPriority = "1"
        message = message.minus("[H]")
    }
    if(message.startsWith("[E]")){
        customPriority = "2"
        message = message.minus("[E]")
    }
    if(customPriority){ priority = customPriority}
    
////////////////////////////////////////ADDED BY STEPHACK//////////////////////////////////////////////////////////////////////////////    
    def myUrl = settings["url"]
    def myTitle = settings["urlTitle"]
    //log.debug myUrl
    if(message.contains("[LOC]")){
        incMessage = message.tokenize("[LOC]")
        message = incMessage[0]
        myUrl = incMessage[1]
        myTitle = "Location Link"
        log.debug incMessage
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    // Define the initial postBody keys and values for all messages
    def postBody = [
        token: "$apiKey",
        user: "$userKey",
        message: "${message}",
        priority: priority,
        sound: sound,
        url: myUrl,    ///////////Changed url to myUrl - stephack
        device: deviceName,
        url_title: myTitle, ////////Changed urlTitle to myTitle - stephack
        retry: retry,
        expire: expire
    ]

    if (deviceName) { log.debug "Sending Message: ${message} Priority: ${priority} to Device: $deviceName"}
    else {log.debug "Sending Message: [${message}] Priority: [${priority}] to [All Devices]"}

    // Prepare the package to be sent
    def params = [
        uri: "https://api.pushover.net/1/messages.json",
        contentType: "application/json",
        requestContentType: "application/x-www-form-urlencoded",
        body: postBody
    ]

    if ((apiKey =~ /[A-Za-z0-9]{30}/) && (userKey =~ /[A-Za-z0-9]{30}/)) {
        httpPost(params){response ->
            if(response.status != 200) {
                sendPush("ERROR: 'Pushover Me When' received HTTP error ${response.status}. Check your keys!")
                log.error "Received HTTP error ${response.status}. Check your keys!"
            }
            else {
                log.debug "Message Received by Pushover Server"
        }
        }
    }
    else {
        // Do not sendPush() here, the user may have intentionally set up bad keys for testing.
        log.error "API key '${apiKey}' or User key '${userKey}' is not properly formatted!"
    }
}

EDIT: not sure why the above code looks so strange with the green text. :man_shrugging:

1 Like