Homeassistant notification bot for matrix via webhooks
A maubot bot to get Homeassistant-notifications in your favorite matrix room.
Simple message | Edited message with reaction |
---|---|
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 (โ How to enable encrypted rooms for your maubot). 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 homeassistant 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: "{% if data is mapping and 'type' in data %}{{data.type}}{% endif %}"
identifier: "{% if data is mapping and 'identifier' in data %}{{data.identifier}}{% endif %}"
callback_url: "{% if data is mapping and 'callback_url' in data %}{{data.callback_url}}{% endif %}"
lifetime: "{% if data is mapping and 'lifetime' in data %}{{data.lifetime}}{% endif %}"
The bot is almost stateless (database only used for lifetime) and can be used within multiple rooms.
service: notify.<your_service_name>
data:
message: <your_message>
data:
type: <message / reaction / edit / redaction> # 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 homeassistant 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: 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
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.