Gotify Push Messaging [solved]

Hi all,

This took me a while to figure out, so I thought I’d share a working example of Gotify push messaging in OH rules (working for me in OH4). My use case is a de-Googled phone, and without FCM unfortunately most other push messaging options disappear. Also, being self-hosted it’s one less 3rd party cloud service to depend on.

Note this is simply the rule to dispatch messages from OH. It assumes you already have a reachable and working Gotify server and can successfully send test messages using CURL or similar. I’m afraid those more skilled may find it’s not very elegantly done, but here it is nonetheless.

val String gotify_priority_min = "\r\n--ce3272dc3305bc29\r\nContent-Disposition: form-data; name=\"priority\"\r\n\r\n0\r\n--ce3272dc3305bc29--\r\n"
val String gotify_priority_low = "\r\n--ce3272dc3305bc29\r\nContent-Disposition: form-data; name=\"priority\"\r\n\r\n2\r\n--ce3272dc3305bc29--\r\n"
val String gotify_priority_normal = "\r\n--ce3272dc3305bc29\r\nContent-Disposition: form-data; name=\"priority\"\r\n\r\n5\r\n--ce3272dc3305bc29--\r\n"
val String gotify_priority_high = "\r\n--ce3272dc3305bc29\r\nContent-Disposition: form-data; name=\"priority\"\r\n\r\n9\r\n--ce3272dc3305bc29--\r\n"
val String gotify_first_boundary = "--ce3272dc3305bc29\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n"
val String gotify_second_boundary = "\r\n--ce3272dc3305bc29\r\nContent-Disposition: form-data; name=\"message\"\r\n\r\n"
val String gotify_server = "http://<your Gotify server address xxx.xxx.x.xxx:XXXX>/message?token=<xxxxxxxx  your Gotify app token>"
val String gotify_headers = "multipart/form-data; Boundary=ce3272dc3305bc29\r\n"
var String gotify_headline = null
var String gotify_payload = null


rule "Doorbell Ringing"
when
        Item MYDOORBELL_RINGER changed from OFF to ON
then
            gotify_headline = "Doorbell Alert"
            gotify_payload = "ALERT - Someone rang the doorbell."
            logInfo("Gotify Message", sendHttpPostRequest(gotify_server, gotify_headers, gotify_first_boundary + gotify_headline + gotify_second_boundary + gotify_payload + gotify_priority_high))
end

Needless to say the gotify_priority_high suffix can be substituted for whichever level of urgency you want to give it. The phone app allows 4 different types of alerts to be configured based on the priority, so for example I have unimportant events (min priority) pop a silent on-screen notification, whereas low through to high priority messages have increasingly intrusive alert tones as well as the on-screen message.

Hope this helps someone.

1 Like

Cool thanks for posting, can u give a review of how well it works and any limitations you have seen so. People can work out if this is something worth installing?

Does it work fully offline if your internet goes down?
What delay is there for the message to appear on your phone to when the event happens?

What can you do if you use a client token instead of an app token? Is it easy to setup either one as I read the client token gives more access to more api features.

Sure. My only experience is with the Android client though. Message delivery is pretty close to instantaneous, it’s been completely reliable so far, and hasn’t had a noticeable impact on device battery life, so only praise in that respect.

You get to send with different priorities (you can configure 4 different notification behaviours in Android settings depending on priority), and you can use your own icon for each app.

There’s obviously additional time and effort required to deploy and maintain a server, and you’ll need a suitable hosting environment. Documentation was good though, and I didn’t face any major issues. You’re at the mercy of your own equipment though, and if anything like your hardware or network connectivity goes down you won’t get your messages!

Haven’t explored the question of client token Vs. app token I have to confess. I started out using the app token and haven’t really felt it was lacking anything, and didn’t look any further. Project for the next rainy day perhaps…

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.