How to get actionable notifications using Slack

Thanks for your very detailed guide! I agree with @mot359, definitely very flexible. I took your concept and moved the outbound messaging and inbound actions over to node red for better visibility, debugging and manipulation capabilities. The only thing I noticed was that I needed to specify a name for each attachment action (your example listed the “Leave It” as blank) otherwise it didn’t appear in the message :+1:

You’re right. I noticed that too; I just didn’t click that option enough to notice when I wrote that :slight_smile:

I had the same issue that curl worked fine but nothing else did. I modified the script file (removed extra spaces and tabs) and restarted hassio and then I was able send messages with the rest_command from dev tools. I’m quite sure removing the extra spaces and such was not the issue but something happened after that. I had restarted hassio several times before so that’s probably not it either.

Now the rest_command works but there is something wrong with the script. I’ll keep investigating and see if I get around the issue.

Ok. The script works now for me as well. Here’s what happened. First I tried to test the script from developer tools and eventually gave up. I then created a new automation with an action that called directly the rest command. That worked but wasn’t enough for me. Then after fiddling around for a while I decided to go and modify the automations yaml file directly. I ended up having the following action for my automation.

  action:
  - data_template:
      channel: XXX
      message: 'something'
    service: script.notify_slack

That works perfectly. The only change to the original is that the data_template and service switched places. The down side is that for some reason the dev tools still doesn’t work with the script and automation ui is not able to show my action (only in yaml mode which is totally fine).

In short: 1) Forget about the dev tools. 2) Modify the automations.yaml.

That is definitely strange. I tested all of that functionality via the dev tools when I was developing it. Although, I haven’t ever used the automation UI, only YAML editing.

I’ve got two weird issues here. I’ve copied your attachments section verbatim including the two buttons, but I only get the first button and not the second. Any thoughts on why?

Secondly, is anyone else having an issue where the app’s bot’s messages don’t send you notifications? They appear and are unread in the app but my phone doesn’t actually notify me of the new messages (if say Slack is closed). Maybe I set my bot up wrong?

You need to add a name for the second button. The OP example shows it as ‘’, but you need to actually populate it.

@SteveDinn - if possible can you please edit the first post?

Do you have slack open on your desktop also? There’s an option to not send to your phone if the desktop is active

For sure…I had thought I already did this.

Read this:

In particular, this bit:

It’s definitely a limitation.

Wow. Dumb question on my part re mobile notifications. Working this morning. Thanks guys looks great.

Did you need to insert the callback_id in the interactive components list in the slack app options as well? Are free accounts limited to 5 actions as a result?

No, these callback IDs are completely arbitrary and defined by your notifications. Slack doesn’t have to know anything about them; it just parrots them back when you click a button.

Awesome. You might want to point that out for us slack-app newbies as well in the OP.

This even seems to work well with the current iteration of the slack integration. It might be worth changing the docs to reflect creation of an app rather than just a bot. Only apps can do these actionable notifications - basic bots not associated with an app cannot.

I ended up having to rebuild my system without the aid of how I had done it before, but that was a great chance to follow this perfectly. However, I ran into one problem at the final step.

What is the purpose of the final part of the cover_left_open_callback script,specifically, “…else entity[6:]” line? I don’t use covers, but I changed all of your covers to an input_boolean.dog_fed that I needed it for. My automation kept erroring out on the entity[6:] line (“entity is undefined”) until I changed the attachment action name. Yours is ‘cover.garagedoor’ but my not-working translation was ‘input_boolean.dog_fed’. When that changed to ‘dog_fed’ to bypass the entity[6:] line, it worked perfectly.

My hope is to have a single message allow us to work with multiple entities (e.g. turn on three input_booleans at once, rather than just one). I’m not sure if my lack of understanding of the entity[6:] line will block that. Any tips on how to make that work?

“cover:” is 6 characters. That notation skips the first 6 characters. So when you changed cover to input_boolean, it would have to change to 14 to perform the same function.

Got it. Why do you have that template? Why not just pass entity_id directly?

Some semblance of “security”. I don’t like the idea of something external being able to specify a complete entity id. At least this limits what can be specified. It’s not perfect.

edit: fixed autocorrect.

Makes sense. Thanks again.

I looked at the Slack integration for Hass and then at the python package it uses to communicate with Slack. As far as I can see the api wrapper handles attachments etc, so this should be possible to do natively in hass if someone adds it to the integration. I think that would make it a lot more accessible to everyone. I don’t have the time to do it myself, but wanted to leave this thought here if someone else want’s to take a stab at it :slight_smile:

Hello guys!
I have a problem with attachments. It seems to work perfectly in lovelace, but does not in automation.

EDIT: Fixed by doing the same as: How to get actionable notifications using Slack

Here is the lovelace version:

name: Test Slack
tap_action:
  action: call-service
  service: script.notify_slack_test
  service_data:
    attachments:
      - actions:
          - name: done
            text: Done
            type: button
            value: done
        attachment_type: default
        callback_id: my-custom_callback
        color: '#03a9f4'
        title: Is it done?
    message: You need to make that!
type: button

And here is the automation version (and I make sure the condition is OK):

- id: my-custom-automation
  alias: My custom automation
  trigger:
    - platform: time
      at: "07:00:00"
  condition:
    - condition: template
      value_template: "{{ now().day == 1 or now().day == 16 }}"
  action:
    service: script.notify_slack
    data:
      message: You need to make that!
      attachments:
        - actions:
            - name: done
              text: Done
              type: button
              value: done
          attachment_type: default
          callback_id: my-custom_callback
          color: "#03a9f4"
          title: Is it done?

Any thoughts?

My apologies if I just have a serious lack of reading comprehension.

Set up a callback to perform actions
On https://api.slack.com , when looking at your app, click on “Interactive components” and turn on “Interactivity” . In the “Request URL” box, you’re going to enter the address of a webhook that you’ll create in Home Assistant (something like https://[your domain]/api/webhook/[webhook_id]).

Is that explained here on how to do? I’m actually coming from this NodeRed package and also this guide when I couldn’t get Interactivity/Events setup with my ngrok URL. NR logs say 401.