Borgmatic notifications via Home Assistant

In the past i normally used Telegram for all kinds of notifications in my smarthome and homelab. I mean it simply was easy and convenient with its bot feature. But the platform become more and more ethical problematic in the past years. Thats quite sad because back in 2013 it was a really good alternative to Whatsapp (which i never used). Crossplattform with optional encryption and not owned by some Techbros from Silicon Valley. Nevertheless: nowadays you connect Telegram with Terrorism, Fascists and all kind of bogus people who run their extremist platforms on the Telegram Channel feature. You now could say: dont kill the messenger, but i better chose to migrate.

Migrating my Borgmatic notifications is not hard at all but there is a small caveat because Borgmatic uses yaml files use colons as delimiter, which is kind of bad when you use curl to pass a json payload.

But first of all you need a Webhook endpoint in Home Assistant for your notification. This is really easy done. Navigate to Atutomations & Scenes in HA than add a new automation and paste the following yaml:

alias: Borgmatic backup notification
description: Sends backup notifictaions
triggers:
  - webhook_id: backup_notification
    allowed_methods:
      - POST
    local_only: false
    trigger: webhook
conditions: []
actions:
  - data:
      message: "{{ trigger.json.Message }}"
      title: Backup Status
    action: notify.your_smartphone_etc
mode: single

Remember this is a yaml, so no tabs but spaces for indentation. Obviously you can change alias, description, webhook_id and put your smartphone etc into the action. Thats it for the Home Assistant part.

Next you need to put the correct commands into the Borgmatic config.yaml so that the currect curl command will be triggered when a backup ist started, finished or failed. I will just post the hook section here which is needed.

hooks:
    before_backup:
        - echo "Starting a backup."
        - > 
          /usr/bin/curl -X POST -H "Content-Type: application/json" -d '{"Message":"Started Backup"}' http://YourHAIP:8123/api/webhook/backup_notification
    after_backup:
        - echo "Finished a backup."
        - >
          /usr/bin/curl -X POST -H "Content-Type: application/json" -d '{"Message":"Finisched Backup"}' http://YourHAIP:8123/api/webhook/backup_notification
    on_error:
        - echo "Error during prune/create/check."
        - > 
          /usr/bin/curl -X POST -H "Content-Type: application/json" -d '{"Message":"Backup Error"}' http://YourHAIP:8123/api/webhook/backup_notification

Sorry for the bad formatting in WordPress. The special thing is that you need to use multiline yaml (recognizeable because of the – > ), i tried puttung the whole curl commands in braces which did not work.

Nevertheless, i get me notifications now onto my smartphone via Home Assistant. Dont know if that is the end of the journey or if i will switch one time to Matrix or XMPP for my notifications.

By the way this may not only work with Home Assistant but also with all other services receiving their data via Webhooks and json payload.

Have fun

Björns Techblog
Björns Techblog
@blog@blog.sengotta.net
319 Beiträge
30 Folgende
Fediverse-Reaktionen

Schreibe einen Kommentar