Self Hosted Push Notifications with Gotify

Hi All,

I’ve been looking for a self hosted push notification platform for what seems like forever. Now I think I’ve finally found it: Gotify. The good news is it can be integrated easily with HASS via the REST notification platform.

I’ve written up all the details on my blog (it’s a bit long!):

https://webworxshop.com/self-hosted-push-notifications-with-gotify-and-home-assistant/

Please let me know what you think!

13 Likes

I came across this on your website while reading about the sound system.
This platform is fantastic. Installed it as per your guide and notifications are really instantaneous.
Do share if you work out how to make actionable notifications.

Thank you very, very much for sharing this.

Thanks for the kind feedback!

Yeah, the notifications are really quick, I also get simultaneous notifications on desktop and mobile. I’ve not had chance to get back to looking into actionable notifications yet, but I’ll be sure to write it up when I do.

have you found a way to set priority when sending messages from hass? I tried adding priority in the data extras, but it doesn’t work as i imagined

{
    "title": "Hello World!",
    "message": "Hello from Home Assistant via Gotify",
    "data": { "priority": 8 }
}

I just tried your code and I receive the notifications, but they don’t look any different from the normal ones. To be honest I’m not exactly sure what the priority is supposed to do!

I’m not getting notifications on the android app. Messages are delivered, but according to the docs (https://github.com/gotify/android) one must specify priority above 0 for system phone notifications (eg “Icon in notification bar”).

@robconnolly are you getting actual phone notifications without specifying priority?

Yes, I get system notifications. Have you checked the notification settings for the gotify app? It’s possible your notifications are being silenced by the system.

I don’t actually see anything related to notifications in the app itself… I ended up hardcoding the priority and create a few different services for various priority levels.

notify:
  - name: gotify_priority_10
    platform: rest
    resource: http://.../message
    method: POST_JSON
    headers: 
      X-Gotify-Key: !secret gotify_key
    message_param_name: message
    title_param_name: title
    data:
      priority: 10

I’m thinking there has to be a way to get it to work correctly with data_template, but I wasn’t able to get it to work in reasonable amount of time.

2 Likes

The notification settings for each app are in the device settings, under Apps->Gotify->Notifications for me. Looks like there are some settings in there for different priority levels, but all mine are just set to “Sound”.

Interesting, I found what you are talking about. There are settings for various priority messages and how to react to them.

For clarification, this is in the phone’s system settings, not in the app iteself.

@robconnolly thank you so much for your help!

Yep, exactly. Let me know if these correspond to the priority levels from Gotify. I haven’t had a chance to play around with it yet, but I can imagine it would be useful.

Hi there,

I got stuck exactly at the same point.
Thanks for your hard coded workaround solution ! (a lot better than nothing)
I believe there is a way to define the priority as an added notification parameter using the data: syntax
in the documentation it is mentioned:

data
(string)(Optional)
Dictionary of extra parameters to send to the resource.

…but I failed to “guess” the correct way to do it.
did you ever solved it?

Ended up using multiple notify targets.

I’m curious as well if there has been support added to specify priority in each request. I’ve added message_param_name and title_param_name; those work. I assumed priority_param_name would work as well but it does not.

notify:

  • name: Gotify
    platform: rest
    method: POST
    resource: “https://server
    message_param_name: message
    title_param_name: title
1 Like

thx Rob for this great tutorial!

Did anyone manage to get the priority working without the workaround?

Notify setup

- name: gotify
  platform: rest
  resource: http://tasks.gotify_app/message
  method: POST
  headers: 
    X-Gotify-Key: !secret gotify_hass
  message_param_name: message
  title_param_name: title
  target_param_name: priority

Usage:

title: title
message: message
target: 8

Target is your priority. Enjoy

Note: that your method must be POST and not POST_JSON. As POST_JSON will tell Gotify that your priority value is a string and you will get an error. Setting it to POST lets Gotify decode a Form Post submission and interpret as a number.

1 Like

Thanks, can confirm that works to set priority!
Surprised Gotify isn’t more popular, seems to work well.

@robconnolly

Good day Rob, I noticed Gotify now have additional “extras” in notifications and it looks like there’s actions for android?

gotify

Have you tried these?

Edit:
Ok adding the bottom bit to the extras opens the url

- platform: rest 
  name: juan_gotify 
  resource: https://myserver/message
  method: POST_JSON
  headers: 
    X-Gotify-Key: !secret gotify_jp_key
  message_param_name: message
  title_param_name: title
  target_param_name: priority 
  data:
    extras:
      client::display:
        contentType: "text/markdown"
      client::notification:
        click: { "url": "https://gotify.net" }  

but not sure how to modify the url in the message to change the url. right now it opens https://gotify.net

Edit: April 23, 2021
For those interested in using this feature, below is my own response

- platform: rest 
  name: juan_gotify 
  resource: https://myserver/message
  method: POST_JSON
  headers: 
    X-Gotify-Key: !secret gotify_jp_key
  message_param_name: message
  title_param_name: title
  target_param_name: priority 
  data:
    extras:
      client::display:
        contentType: "text/markdown"
      client::notification:
        click: { "url": "{{states('input_text.gotify')}}" }  

and add the corresponding input_text. you can then set the input_text value during the notification automation.

2 Likes

Thanks for this solution! However I discovered that using the POST method doesn’t let me automatically download images anymore. For my camera images when someone approaches my house this is a must have.

Would you know any solution to this, or is it just the limitation of POST?