It is also possible to self-host the notification server directly on your computer, which avoids going through the third-party server (more secure).
I leave you a working example in python. Good fun to those who are interested ;-)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import locale
from pip._vendor import requests
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
URL_NOTIFY = "
https://ntfy.sh/"
ABONNEMENT_NOTIFY = "MYNOTIF_PARAMETER"
URL_SERVEUR = "
https://meteomillau.pagesperso-orange.fr/"
WEBCAM_FILE = "webcam.png"
ICON_ALERT = "warning,skull"
# Fonction de notification sur téléphone Android ou Iphone via l'application ntfy
# titre correspond au titre du message, message au texte du message, icone aux icones de notication rajoutés (voir plus bas), urgence de 1 à 5,
# click_ok si vrai renvoie sur une addresse http si click sur la notification et image_ok si vrai renvoie l'image png réduite de la WebCam
# En réponse à la procédure notify, le code de retour de la requête put.
# Icones : cloud_with_snow, cloud_with_rain, fog, thermometer, sunny, cold_face, hot_face, tornado, warning
# En fin d'operation, renvoie "True" et code erreur 0 si tout s'est bien passé, sinon False avec le libellé de l'erreur.
def notify (titre,message,icone,urgence,clic_ok,image_ok) :
if clic_ok :
ADDRESSE_CLIC = URL_SERVEUR
else :
ADDRESSE_CLIC = None
if image_ok :
ADDRESSE_IMAGE = URL_SERVEUR + WEBCAM_FILE
else :
ADDRESSE_IMAGE = None
PRIORITY_VALUE = {
1: "min",
2: "low",
3: "default",
4: "high",
5: "urgent"
}
priorite = PRIORITY_VALUE.get (urgence)
headers = {
'Click' : ADDRESSE_CLIC,
'Title' : titre.encode(encoding='utf-8'),
'Attach' : ADDRESSE_IMAGE,
'Priority': priorite,
'Tags': icone,
}
if priorite != None :
try :
reponse = requests.put(URL_NOTIFY + ABONNEMENT_NOTIFY, headers=headers, data=message.encode(encoding='utf-8'))
status_envoie = (reponse.reason=="OK")
erreur = "Notification GSM correctement envoyée"
except Exception as e:
status_envoie = False
erreur = e
else :
status_envoie = False
erreur = "Erreur de notification GSM : niveau d'urgence erroné (0...-> 5)"
return (status_envoie,erreur)
# ---------------------------------> Début du Programme <-------------------------------------
subj = "Alerte météo : TEMPERATURE EXTERIEURE TRES BASSE ( < -5°C ) - **** ! DANGER GEL SEVERE ! ****"
status,code_erreur= notify ("Message d'alerte météo",subj,"warning",None,True,True)
print (status)
print (code_erreur)
exit ()