Automating "lunch" Slack status

Set my Slack status from the Home Automation dashboard.
 2020-04-18

Why?

My work is 100% remote, I work from home most of the time. Although I usually have a stable schedule and try to have meals at the same time every day, sometimes meetings get into way, and I eat earlier or later than usual. To let my co-workers know that I’m currently away, I prefer to set a Slack status (and do not send messages saying “going to lunch” and “back”).

A little over a year ago I started learning Rust, and the best way for me to learn is to get my hands dirty, try to code something simple. As a kind of “hello world” application, I wrote a little command-line utility which lets you change your Slack status, in several Slack accounts at once. Now I could just do slack_status lunch from a command line, and my Slack status changes to “Lunch” in all my work-related Slack accounts. slack_status clear clears the status when I come back. This utility has configurable emojis and status expiration and works very well for me.

Integrating with home automation dashboard

I noticed that this sequence of events happened quite often:

  • My wife prepares lunch and calls me using our food is ready! system.
  • I get up, go to the office door to turn off the bell on the tablet.
  • I remember that I didn’t set the Slack status, go back to my computer to set it.
  • I finally go upstairs to have lunch.

So I integrated this little slack_status utility right into my home automation dashboard!

Integrating with Home Assistant

Since slack_status is written in Rust, it’s pretty trivial to compile it and copy the binary to the Home Assistant host. There are no run-time external dependencies. I edited the configuration file to set the needed secrets, and then configured Home Assistant to call this binary. Home Assistant supports a generic “command-line” switch type, so this is pretty simple:

switch:
  - platform: command_line
    switches:
      slack_lunch:
        friendly_name: "Slack 'Lunch' status"
        command_on: /usr/local/bin/slack_status lunch
        command_off: /usr/local/bin/slack_status clear

Integrating with the dashboard

Hadashboard already support Home Assistant switches, so all I needed to do is to pick up the right icon. Here’s my Dashboard widget config:

<li data-row="1" data-col="7" data-sizex="1" data-sizey="1">
    <div data-id="slack_lunch" data-view="Haswitch" data-title="Lunch" data-icon="mdi:food"></div>
</li>

Demo

Here is how it works:

Limitations

You may have noticed that the Home Assistant > Slack communication is unidirectional, and any change applied directly in Slack is not reflected in the dashboard. I think the proper way to handle this is to enhance the existing Slack integration in Home Assistant, which does not support status changes in any shape or form at this time. Could be a fun weekend project to tackle one day…

See also

Wall-mounted Dashboards (part 2)

Tablet firmware and software.

Wall-mounted Dashboards (part 1)

Initial planning, hardware, mounting, power supplies.