From e2dbd69c5e428b94b1b7966b257f304a890e87e1 Mon Sep 17 00:00:00 2001 From: Rasmus Lundsgaard Date: Mon, 14 Jul 2025 13:59:07 +0200 Subject: [PATCH] first version of notification to Home Assistant (#213) * first working version of notification to Home Assistant * add documentation links * update readme for notify_HA --- README.md | 2 ++ default.config | 7 ++++++- notify_templates/notify_HA.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 notify_templates/notify_HA.sh diff --git a/README.md b/README.md index dfac061..6fec3fc 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ Make certain your project directory is laid out as below. You only need the noti │ ├── notify_discord.sh │ ├── notify_generic.sh │ ├── notify_gotify.sh +│ ├── notify_HA.sh │ ├── notify_matrix.sh │ ├── notify_ntfy.sh │ ├── notify_pushbullet.sh @@ -190,6 +191,7 @@ If an update becomes available for an item that is not snoozed, notifications wi - Read the [QuickStart](extras/apprise_quickstart.md) - [ntfy](https://ntfy.sh/) - HTTP-based pub-sub notifications. - [Gotify](https://gotify.net/) - a simple server for sending and receiving messages. +- [Home Assistant](https://www.home-assistant.io/integrations/notify/) - Connection to the notify [integrations](https://www.home-assistant.io/integrations/#notifications). - [Pushbullet](https://www.pushbullet.com/) - connecting different devices with cross-platform features. - [Telegram](https://telegram.org/) - Telegram chat API. - [Matrix-Synapse](https://github.com/element-hq/synapse) - [Matrix](https://matrix.org/), open, secure, decentralised communication. diff --git a/default.config b/default.config index 27bb52c..49457f0 100644 --- a/default.config +++ b/default.config @@ -32,7 +32,7 @@ ## All commented values are examples only. Modify as needed. ## ## Uncomment the line below and specify the notification channels you wish to enable in a space separated string -# NOTIFY_CHANNELS="apprise discord DSM generic gotify matrix ntfy pushbullet pushover slack smtp telegram" +# NOTIFY_CHANNELS="apprise discord DSM generic HA gotify matrix ntfy pushbullet pushover slack smtp telegram" # ## Uncomment the line below and specify the number of seconds to delay notifications to enable snooze # SNOOZE_SECONDS=86400 @@ -57,6 +57,10 @@ # GOTIFY_DOMAIN="https://gotify.domain.tld" # GOTIFY_TOKEN="token-value" # +# HA_ENTITY="entity" +# HA_TOKEN="token" +# HA_URL="https://your.homeassistant.url" +# # MATRIX_ACCESS_TOKEN="token-value" # MATRIX_ROOM_ID="myroom" # MATRIX_SERVER_URL="https://matrix.yourdomain.tld" @@ -82,3 +86,4 @@ # TELEGRAM_CHAT_ID="mychatid" # TELEGRAM_TOKEN="token-value" # TELEGRAM_TOPIC_ID="0" + diff --git a/notify_templates/notify_HA.sh b/notify_templates/notify_HA.sh new file mode 100755 index 0000000..dda74be --- /dev/null +++ b/notify_templates/notify_HA.sh @@ -0,0 +1,31 @@ +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +NOTIFY_HA_VERSION="v0.1" +# +# This is an integration that makes it possible to send notifications via Home Assistant (https://www.home-assistant.io/integrations/notify/) +# You need to generate a long-lived access token in Home Sssistant to be used here (https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token) +# Leave (or place) this file in the "notify_templates" subdirectory within the same directory as the main dockcheck.sh script. +# If you instead wish make your own modifications, make a copy in the same directory as the main dockcheck.sh script. +# Do not modify this file directly within the "notify_templates" subdirectory. Set HA_ENTITY, HA_URL and HA_TOKEN in your dockcheck.config file. + +if [[ -z "${HA_ENTITY:-}" ]] || [[ -z "${HA_URL:-}" ]] || [[ -z "${HA_TOKEN:-}" ]]; then + printf "Home Assistant notification channel enabled, but required configuration variables are missing. Home assistant notifications will not be sent.\n" + + remove_channel HA +fi + +trigger_HA_notification() { + AccessToken="${HA_TOKEN}" + Url="${HA_URL}/api/services/notify/${HA_ENTITY}" + JsonData=$( "$jqbin" -n \ + --arg body "$MessageBody" \ + '{"title": "dockcheck update", "message": $body}' ) + + curl -S -o /dev/null ${CurlArgs} \ + -H "Authorization: Bearer $AccessToken" \ + -H "Content-Type: application/json" \ + -d "$JsonData" -X POST $Url + + if [[ $? -gt 0 ]]; then + NotifyError=true + fi +}