mirror of
https://github.com/mag37/dockcheck.git
synced 2026-02-20 18:24:15 +01:00
first version of notification to Home Assistant (#213)
* first working version of notification to Home Assistant * add documentation links * update readme for notify_HA
This commit is contained in:
parent
98e996caa3
commit
e2dbd69c5e
3 changed files with 39 additions and 1 deletions
31
notify_templates/notify_HA.sh
Executable file
31
notify_templates/notify_HA.sh
Executable file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue