How to Display Active Slack Users on Your AWTRIX Clock Using MQTT

    Written by Sebastien Perusat

    Ever wondered how many people are active in your Slack workspace right now? What if you could glance at your desk and see that number in real-time displayed right on your AWTRIX clock?

    That’s exactly what I set out to do.

    This tutorial walks you through how to automate the active Slack user count and publish it live to your AWTRIX clock using MQTT. It’s geeky, useful, and a ton of fun especially if you’re a fan of community metrics and automation like I am.


    What You’ll Learn

    • How to pull real-time active user data from the Slack API
    • How to automate updates to your Homematic IP CCU
    • How to publish live data to your AWTRIX Blueforcer (Ulanzi TC001)
    • Bonus: MQTT publishing made simple!

    Prerequisites

    Before we start, make sure you have the following:

    • Slack API token
    • Homematic IP CCU credentials and endpoint
    • MQTT broker (e.g., Mosquitto)
    • Installed: curl, jq, mosquitto_pub
    • An AWTRIX clock (running Blueforcer firmware)

    The Script: Counting Slack Users & Broadcasting via MQTT

    Here’s the shell script that does it all counts active Slack users, updates your Homematic IP CCU, and broadcasts the number to AWTRIX.

    #!/bin/sh
    # Slack to AWTRIX Automation Script
    # Author: Sebastien Perusat

    SLACK_TOKEN="xoxb-..." # Add your Slack API token
    CCU_ENDPOINT="http://your_ccu_endpoint"
    CCU_USER="api_user"
    CCU_PASSWORD="your_password"
    SLACKUSERCOUNT_VARIABLE="yourCCUvariable"
    mqtt_broker="your_mqtt_broker_address"
    mqtt_topic="awtrix/customapp"

    LOG_FILE="/var/log/slack-api-$(date +%F).log"
    log_message() {
    echo "$(date): $1" >> "$LOG_FILE"
    }

    count_and_update_slack_users() {
    local cursor=""
    local total_active_users=0
    while :
    do
    response=$(curl -s -H "Authorization: Bearer $SLACK_TOKEN" "https://slack.com/api/users.list?limit=1000&cursor=$cursor")
    [ $? -ne 0 ] && return 1
    active_user_count=$(echo $response | jq '[.members[] | select(.deleted == false)] | length')
    total_active_users=$((total_active_users + active_user_count))
    cursor=$(echo $response | jq -r '.response_metadata.next_cursor')
    [ -z "$cursor" ] && break
    done

    log_message "Active Slack users: $total_active_users"

    # Update Homematic CCU
    url="$CCU_ENDPOINT?Antwort=dom.GetObject(\"$SLACKUSERCOUNT_VARIABLE\").State(\"$total_active_users\")"
    curl -k --user "$CCU_USER:$CCU_PASSWORD" "$url" || log_message "Failed to update CCU"

    # Publish to MQTT
    mqtt_message="{\"icon\":10977,\"text\":\"Active Users: $total_active_users\"}"
    mosquitto_pub -h "$mqtt_broker" -t "$mqtt_topic" -m "$mqtt_message"
    log_message "MQTT Published: $mqtt_message"
    }

    main() {
    log_message "Script started"
    count_and_update_slack_users
    log_message "Script ended"
    }

    main "$@"

    How It Works

    Step-by-step breakdown:

    1. Query Slack using their API and paginate results with a cursor.
    2. Count non-deleted users (i.e., active members).
    3. Update CCU with the current count.
    4. Push to MQTT to trigger the update on your AWTRIX.

    All automated, all in real-time.


    Why This Hack Rocks

    • Real-Time Insights: Know exactly how many are online at a glance!
    • Automation Win: Set it, forget it, enjoy it.
    • Community Love: Every active IGEL member matters. Now you see them!

    How to Set It Up Yourself

    1. Generate a Slack API token from your workspace.
    2. Configure your CCU credentials and endpoint.
    3. Replace placeholders in the script with your actual values.
    4. Install dependencies: jq, curl, mosquitto_pub.
    5. Schedule via cronjob or run manually. Done!

    Final Thoughts

    This project blends automation, community, and real-time feedback in a way that’s not only practical but super satisfying. Got a cool use case for MQTT or AWTRIX? Want to share your own Slack automation? Let’s chat!

    And remember: every new IGEL Community member deserves a place on your clock. 😉


    Keywords: Slack active user count, AWTRIX MQTT integration, automate Slack data, community dashboard, shell script Slack API, IGEL community tools, display Slack data on AWTRIX

    Leave a Reply

    Your email address will not be published. Required fields are marked *