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.