Git Product home page Git Product logo

hasswebhookbot's Introduction

GitHub release (latest by date) GitHub Workflow Status

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
Imgur Imgur

Configuration

First add this plugin to your maubot manager:

  1. Load the *.mbp file of the current release
  2. Create client and instance
  3. 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 %}"

Usage

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

Examples

Send a message

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

Delete a 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

React to message

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

Edit message

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:

  1. Content of <del></del> is discarded in the Matrix notification (keep_del_tag: true)
    Notification example:
* - New message
  1. 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.

hasswebhookbot's People

Contributors

alexanderbabel avatar v411e avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.