Send notification to Mattermost

Hi,

I’m trying to send a message from HA to Mattermost. I have a shell script, a perl script and a curl command that can do this from the command line.

The perl script or the shell script would be the preferred method. However, I don’t see how to parameterize the message text. For example I would like to execute this command:

./notify.pl “This is a message” “@user

But all I can ever get to work is:

./notify.pl

The alternative is to use a REST notifier. I’ve tried various variations of this theme:

notify:

  • platform: rest
    name: NotifyMe
    method: POST
    headers:
    Content-Type: application/json
    resource: https://mm.example.com/hooks/nceur8
    data:{text: “This is a test”, message: “this is a message” }
    message_param_name: text

But when I run this notifier, the Mattermost logs indicate that the message body is null.

The curl command that works from the command line looks like this:

curl -i -X POST -H ‘Content-Type: application/json’ -d ‘{“text”: “Hello, this is some text\nThis is more text” }’ https://mm.example.com/hooks/nceur8

So, I hope you can see what I’m trying to do.

What am I missing?

Mike.

I’ve been working on it for my instance as well and it’s fairly simple once we dig into Mattermost’s documentation.
Below is what I’m using it seems to get the job done thus far. I’m sure we’d need to test more to get more robust notifications but at least for now we have text.

notify:
  - name: mattermost
    platform: rest
    resource: https://your-mattermost-server.com/hooks/xxx-generatedkey-xxx
    method: POST_JSON
    message_param_name: text

That worked for me! Thank you!

Is the generated key the personal access token? Also, is this just a service after integrated to add to automation?

Yes, the generated key is just a personal access token. If I understand your question correctly, yes, this creates a service that I can call in an automation to send a message to someone via Mattermost.

Hope that helps.

Mike