BackEnd: HA to MatterMost via WebHook

I am going to be uploading a series of messages. I have been working on getting HA to send messages to Matter Most with WebHooks.

In HA I am using a shell script, which to say the least is very confusing as to what file is where and when. On Matter Most I have a special channel for the messages to be sent into. This is all done via WebHooks.

I am going to break this up into a series of messages so if you need to ask questions I will be happy to reply.

Greg

On my MatterMost I created a channel for the new messages to be stored in. I found this to be the simplest way of controlling the messages as you will see shortly.

In MatterMost as an Administrator go to the channel creation tool. In the MatterMost program this option is found under the + sign at the top of the Channel Column.

  1. Create the channel as normal.
  2. Created you need to create the Webhook key for the channel messages.
  • Select the menu button on MatterMost (3x3 dot square top left)
  • Select Integrations.
  • Select Incoming Webhooks
  • Click ‘Add Incoming Webhook’
    Fill in the Title and Description for the channel then select the channel. Then for safety I select ‘Lock to this channel’. That way if the Webhook key gets out it can only be used to send messages to this channel.

Now click SAVE. You should get a Setup Successful message and a URL.
Copy This URL Down!! I can not stress this enough, you will need this a lot.
If you did not coping it down you can look it up. (I wont go into how here, but is in the MM documentation)

You have not created the Channel for your incoming messages.

The Home Assistant Side is a lot more particular about how you do things. On my system I am running HASSIO patched up to date.
You will need a few Add-On’s to create and test everything. For me getting part to talk properly to every other part was 4 weeks of banging my head on the wall and learning more about Docker than I ever wanted to in my life.

Add-On’s I used to do this:
Home Assistant Add-on: File editor
Home Assistant Community Add-on: Advanced SSH & Web Terminal

I have protected mode disabled when doing this, so be careful!
1 Create the script file with the file editor.
Create the file in the same directory as your config yaml files. I called mine mm-what.sh where what was the picture file I wanted to send.

#! /bin/bash
curl -i --insecure -X POST --data-urlencode 'payload={"attachments": [ { "fallback": "test", "color": "#ff8000", "text": "Picture below.", "author_name": "Home Assistant Monitor", "author_icon": "https://mattermost.com/wp-contect-uploads/2022/02/icon_WS.png", "text": "http://10.10.10.75:8123/local/tmp/porch.jpg", "title": "Porch Motion Detected!" } ] }' https://mattermost.yoururl.com/hooks/<<< your webhook key >>>>

https://mattermost.yoururl.com/hooks/<<< your webhook key >>>> is the URL you copied from MatterMost. This is a work in progress for a lot of what is being sent right now was put there for testing. Alter to fit your tastes. Still being working on is the sending of the actual picture to MatterMost not just the URL where it is found.

In the file editor create the service name needed to send the MatterMost message. This is done in the configuration.yaml file. My section looks like:

shell_command:
  mm_webhook: './mm-porch.sh'

The first two are not relavent to the mm_webhook is the wervice name that the Automation will call. the file that will be called is ./mm-porch.sh which is stored in the same directory as your configure.yaml file.

I did create the automation in the GUI here is the resulting Yaml file:

alias: Porch Activity
description: ""
trigger:
  - type: occupied
    platform: device
    device_id: 6b8ebb2b5e0e51c4cfdbba7b8b947e69
    entity_id: af89c381870919e289cafeddb922d96b
    domain: binary_sensor
condition: []
action:
  - service: camera.snapshot
    data:
      filename: www/tmp/porch.jpg
    enabled: true
    target:
      entity_id: camera.porch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: notify.mobile_app_sm_x200
    data:
      message: Porch Activity
      title: Activity At The Front Door
    enabled: true
  - service: shell_command.mm_webhook
    data: {}
mode: single

This file does the following:

  1. Wait for motion to be detected on the porch.
  2. Take a snapshot of what caused the motion sensor to trigger and store it in the www/tmp/porch.jpg file. Note you will need to create the tmp directory under your /homeassistant/www directory. NOTE in the file name do not put a leading /.
  3. Send a test message to my HA app running on my Android phone.
  4. Send a message to matter most using the service call.

I hope people file this useful in some way. I have got a lot of help from fellow users and I did notice a lot of people trying to so something like this. If you have any questions please send me a message or reply to this thread.

1 Like

Just crossposting how I made a Mattermost integration