Home Assistant notification bot for matrix via webhooks
A maubot bot to get Home Assistant notifications in your favorite matrix room.
Simple message | Edited message with reaction | Image |
---|---|---|
I am describing in this blog post how I use this bot to get notified whenever my washing machine has finised.
First add this plugin to your maubot manager:
- Load the *.mbp file of the current release
- Create client and instance
- Configure instance
base_url
After setting up the plugin just invite the bot into an encrypted room. Each room has an indvidual "webhook url". To get yours just write !ha
. The bot replies with the WEBHOOK_URL
of your room and also generates some YAML code for the configuration of your home assistant instance (like below).
configuration.yaml
on HA (don't forget to reload):
notify:
- name: HASS_MAUBOT
platform: rest
resource: "<WEBHOOK_URL>"
method: POST_JSON
data:
type: "{{data.type}}"
identifier: "{{data.identifier}}"
callback_url: "{{data.callback_url}}"
lifetime: "{{data.lifetime}}"
content: "{{data.content}}"
contentType: "{{data.contentType}}"
name: "{{data.name}}"
thumbnailSize: 512
The bot is almost stateless (database only used for lifetime) and can be used within multiple rooms.
Most attributes are optional. The only attribute that always has to be provided through home assistant is data: message
. You can set this to None
if you are not using it (e.g. sending a redaction or image)
service: notify.<your_service_name>
data:
message: <your_message>
data:
type: <message / reaction / edit / redaction / image> # The type of action
identifier: <letterbox.status / event_id.$DRTYGw...> # Use your own identifier (#1) or reference an event_id (#2)
callback_url: https://<your home assistant instance>/api/webhook/<some_hook_id> # Optional: Get a callback with entity_id of sent message
lifetime: 1440 # Optional: Activate message self-deletion after given time in minutes
service: notify.hass_maubot
data:
message: Die Post ist da! π¬
data:
type: message
identifier: letterbox.status
callback_url: https://ha.example.com/api/webhook/some_hook_id
lifetime: 1440
service: notify.hass_maubot
data:
message: "hi"
data:
type: "message"
service: notify.hass_maubot
data:
message: None
data:
type: redaction
identifier: letterbox.status
or
service: notify.hass_maubot
data:
message: None
data:
type: redaction
identifier: event_id.$DRTYGw... # event_id can be obtained through callback
service: notify.hass_maubot
data:
message: π¬
data:
type: reaction
identifier: letterbox.status
or
service: notify.hass_maubot
data:
message: π¬
data:
type: reaction
identifier: event_id.$DRTYGw... # event_id can be obtained through callback
service: notify.hass_maubot
data:
message: <del>Die Post ist da! π¬</del>
data:
type: edit
identifier: letterbox.status
or
service: notify.hass_maubot
data:
message: <del>Die Post ist da! π¬</del>
data:
type: edit
identifier: event_id.$DRTYGw... # event_id can be obtained through callback
service: notify.hass_maubot
data:
message: None
data:
type: "image"
content: "iVBORw0KGgoAAAANSUhEUgAAADcAAAA5CAYAAACS0bM2AAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAAqdEVYdENyZWF0aW9uIFRpbWUARGkgMjYgU2VwIDIwMjMgMTU6NDU6NDEgQ0VTVJ19+pEAAA6gSURBVGiB7ZrZjxxHcsZ/kVlH391z8D5EUtTqWK4t2bteywdgwH7wf23AgLwP8kKyFzqWEkWKkkiRQ07P9F1HZvghqntIikONLqx3oQQGM91T3RVfRmTEF1+UqKryF7rcn9qAn3L9DO7Pdf0M7s91JT/Fl07KyH4ROSwjs1pZ1FAo1BFCk5u9QOIgF+gk0EuEYebYzh2D7MfZ8x8FXFQoorKqlVWEe/Oau7Oa+8vIo5UyLpV5gFU0gGDAWg66HrYyYbclnGs7LvcSzncTWg5aiZA7wcn3s0t+aJ2LCmVUPpvUfHBQ8elMeVwo81qpolIr1Aqqdu36ZgI4ARFImp/UCd1E2MmF6z3hl6OUa4OE7HsC/EHgxkXk3jJwexa5Mwt8OQ88LJRlOAq/tU2qihcLR7D/B11fcGS5F2h7OJ0LF7ueKz3P1Z7jfNuzlX+3cP1e4ILCrIp8Mqn5n3HFe+PIuFSqeMwHVAFlkAr9RBBgUkUOqyNwIt90TeosZN/acvz1Vsorg4Re6jYb9JOAOywjv3tY8v645tOZsghKHY9C7mlcikNpOeXGKOWXWwkCfDAu+d/9mmUARBDnLEafNA47mx1vYfrmVsLbpzOGJ0w43zmhfDEPfHhQ8+7jmruLyEF5/LUKpMAgFa73PW9uJ7w2tFumYofw5qRmUil14BsAFSgDlEG5NVOqWCMivDFKuNT1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"image/png"
name: "halogo.png"
The image sending functionality is contributed and used by https://github.com/AlexanderBabel/mail-parser.
Hint: Depending on your preference, you can choose between two different modes for the edit feature:
- Content of
<del></del>
is discarded in the Matrix notification (keep_del_tag: true
)
Notification example:
* - New message
- Content of
<del></del>
is displayed as normal text (keep_del_tag: false
)
Notification example:
* Previous message - New message
You can change this setting on the maubot configuration page.