I am in multiple Slack teams and have messages coming in frequently throughout the day. I am also on phone calls with clients all day who don't want to feel like I'm distracted during the call. I could put myself DND (do not disturb) on each slack instance but that's time consuming and I cannot always predict when I'll have a call.
I found a brilliant Slack app, called "OTTT", that allows you to issue slash commands to set your DND for a specified amount of time. To make this more awesome it also allows you, for a modest service fee, to link your Slack team instances so that one slash command sets all of your workspaces to DND. [u]This is what I need![/u]
Now with use of the Ariela app call state sensor and the Slack notify component, with a few small tweaks, I can auto DND when I'm on a call....ah, sweet silence.
- Create a folder called "slack" in your "custom_components" folder in Home Assistant directory.
NOTE: If this is your first custom component you may need to create it. It must be in the same folder that your configuration.yaml file exists
-
Use the files from this gist and place them in individual files. Each file in the gist has the required file names (manifest.json, notify.py, __init__.py).
-
The chat.command API, which does all the magic, isn't officially supported so we need a Legacy Token for this to work. Go to https://api.slack.com/custom-integrations/legacy-tokens, under "Legacy Token Generator" should be a table with your Workspace listed. Click the green button to "Create Token". Keep the page open to copy the token in a later step.
-
Setting up the component configuration in Home Assistant, now, is the same as following the Home Assistant configuration steps https://www.home-assistant.io/integrations/slack.
NOTE: I repeat "configuration" a couple times there because you do not want to follow their "Setup" section instructions.
NOTE 2: This is also where you need to copy/paste your token from step 3.
-
Restart Home Assistant.
-
In Developer Tools -> Services type in notify.slack (or whatever you named it in your configuration) under "Service". If it shows up you're in business. If not try walking through the steps again, or post your error.
Extra credit: Since you're on the services page give it a test with a payload like "message: Hello there!" or "message: /shrug" you should see it show up in the default channel specified in the configuration setup.
Another way I use the Slack Slash Commands in my automations is through another app called “Picker”. This one is a bit of a shameless plug as it’s a slack app I actively work on but the app allows me to solve the problem of “who will do what and when?”
Chore Scenarios:
The laundry is done: html.notify (my family channel) /pick chore fold the laundry
and the response @Costr you have been picked to complete the chore: fold the laundry...
It’s trash day tomorrow /pick task take the trash to the curb
and the response @Mom you have been picked to complete the task: take the trash to the curb...
You could use this with other apps like /remind
or get silly with /shrug
if something happens
Also, if you go the same route and use OTTT this is my automation.
- alias: OTTT On Call Status
trigger:
- entity_id: sensor.phonel_call_state_sensor
platform: state
to: offhook
condition: []
action:
- data:
message: /ottt 480 -q
target:
- '#home-automation'
service: notify.slack
initial_state: 'true'
Note: Notice the -q on the slash command, or message. This is to make the post silent so that you don’t add a line to your slack instance every time this runs. This is something I requested from the OTTT developer and he added in.
- id: '1554931223593'
alias: OTTT Off Call Status
trigger:
- entity_id: sensor.phone_call_state_sensor
from: offhook
platform: state
to: idle
condition: []
action:
- data:
message: /ottt end
target:
- '#home-automation'
service: notify.slack
initial_state: 'true'