Power Outage Data in Slack and Microsoft Teams

To get power outage alerts into Slack or Microsoft Teams, run a Python poller every 15 minutes that sends your sites' coordinates to the PowerOutage.us v2 REST API and posts to a Slack incoming webhook, a Teams Workflows webhook, or both, whenever a site falls inside an outage or comes out of one. A small state file remembers what has been announced, so each outage is posted once with its utility, customers out, cause and estimated restoration, and once more when it no longer covers the site. Teams uses the Workflows app, because Office 365 Connectors, including connector-based incoming webhooks, were retired in May 2026.

What you'll have

  • A message in your ops channel as soon as a utility reports an outage covering one of your sites, naming the utility, customers out, cause and estimated restoration.
  • One message per change, not per run: the poller posts when a site enters an outage and when the outage no longer covers it.
  • The same alert in Slack and Teams from one poller, or in either one alone.
  • Up to 100 sites per request, with every site that changed in a run grouped into one message.

What you need

An API key (request one with the form below) and these endpoints. Full details are in the API reference.

EndpointMethodUsed forPackage
/geojson/at-pointPOSTChecks up to 100 site coordinates per request and returns, in request order, the active outages covering each one and the utilities serving it.Standard + Locations

Step 1: Create a Slack incoming webhook

Skip this step if you only use Teams. At api.slack.com/apps, select Create New App and create an app in your workspace; a workspace admin may need to approve it. Open Incoming Webhooks, turn on Activate Incoming Webhooks, select Add New Webhook to Workspace, choose the channel and authorize. For a private channel you must be a member first. Copy the URL that starts with https://hooks.slack.com/services/. Anyone with it can post to the channel, and Slack revokes webhook URLs it finds published, so store it like a password.

Step 2: Create a Teams Workflows webhook

Skip this step if you only use Slack. In Teams, open the channel, select More options (...) next to its name, then Workflows, and pick the Send webhook alerts to a channel template. Confirm the team and channel, save, and copy the webhook URL the workflow shows. That template posts each Adaptive Card it receives, and anyone with the URL can trigger it, so treat the URL as a secret too. The workflow belongs to the person who created it: add a co-owner so it keeps running if that person leaves.

Step 3: List your sites

/geojson/at-point is in the Standard + Locations package, and the poller depends on it. Give each site a unique id, the name people will read in the channel, and coordinates in decimal degrees.

json
[
  {"id": "store-101", "name": "Store 101, Atlanta", "lat": 33.749, "lon": -84.388},
  {"id": "store-214", "name": "Store 214, Savannah", "lat": 32.0809, "lon": -81.0912}
]

Step 4: Write the poller

Save this as /opt/poweroutage/poweroutage_chat.py. It uses only the Python standard library. It checks your sites in batches of 100, waiting the Retry-After seconds after a 429, three tries at most. Each site and outage pair gets a key built from the site id, utilityId and outageId. Pairs not in the state file are posted under Power outage at N watched site(s), and pairs in the state file that are gone are posted under Outage no longer reported. Slack gets text in its mrkdwn format, with &, < and > escaped; Teams gets an Adaptive Card with one text block per line. The state file is written only after every post succeeds, so a failed post is repeated on the next run, which can repeat a message on the platform that did succeed. Leave out either webhook variable to post to the other platform only.

python
import json
import os
import sys
import time
import urllib.error
import urllib.request
from pathlib import Path

API_KEY = os.environ['POWEROUTAGE_API_KEY']
SLACK_WEBHOOK_URL = os.environ.get('SLACK_WEBHOOK_URL')  # set one or both
TEAMS_WEBHOOK_URL = os.environ.get('TEAMS_WEBHOOK_URL')
if not (SLACK_WEBHOOK_URL or TEAMS_WEBHOOK_URL):
    sys.exit('Set SLACK_WEBHOOK_URL, TEAMS_WEBHOOK_URL or both; nothing was sent or saved.')
# [{"id": "store-101", "name": "Store 101, Atlanta", "lat": 33.749, "lon": -84.388}, ...]
SITES = json.loads(Path(os.environ['SITES_FILE']).read_text())
STATE_FILE = Path(os.environ['STATE_FILE'])  # outages already announced, kept between runs


def call(url, body):
    """POST a JSON body to PowerOutage.us, waiting out a 429 for as long as Retry-After says."""
    request = urllib.request.Request(
        url,
        data=json.dumps(body).encode(),
        headers={'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json'},
    )
    for attempt in range(3):
        try:
            with urllib.request.urlopen(request, timeout=30) as response:
                return json.load(response)
        except urllib.error.HTTPError as err:
            if err.code != 429 or attempt == 2:
                raise
            time.sleep(int(err.headers.get('Retry-After', '10')))


def post(url, body):
    request = urllib.request.Request(
        url, data=json.dumps(body).encode(), headers={'Content-Type': 'application/json'}
    )
    with urllib.request.urlopen(request, timeout=30) as response:
        response.read()


def notify(title, lines):
    if len(lines) > 40:  # keeps a Teams card under its 28 KB limit
        lines = lines[:40] + [f'...and {len(lines) - 40} more']
    if SLACK_WEBHOOK_URL:
        text = f'*{title}*\n' + '\n'.join(lines)
        # Slack reads <, > and & as markup, so escape them
        text = text.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
        post(SLACK_WEBHOOK_URL, {'text': text})
    if TEAMS_WEBHOOK_URL:
        post(TEAMS_WEBHOOK_URL, {
            'type': 'message',
            'attachments': [{
                'contentType': 'application/vnd.microsoft.card.adaptive',
                'content': {
                    '$schema': 'http://adaptivecards.io/schemas/adaptive-card.json',
                    'type': 'AdaptiveCard',
                    'version': '1.2',
                    'body': [{'type': 'TextBlock', 'text': title, 'weight': 'Bolder', 'wrap': True}]
                    + [{'type': 'TextBlock', 'text': line, 'wrap': True} for line in lines],
                },
            }],
        })


current = {}  # site + outage key -> (label, details)
for i in range(0, len(SITES), 100):  # up to 100 points per request
    batch = SITES[i : i + 100]
    result = call(
        'https://poweroutage.us/api/v2/geojson/at-point',
        {'points': [{'lat': s['lat'], 'lon': s['lon']} for s in batch]},
    )
    for site, point in zip(batch, result['data']['points']):  # same order as the request
        names = {u['utilityId']: u['name'] for u in point['utilities']}
        for outage in point['outages']:
            key = f"{site['id']}|poweroutage:{outage['utilityId']}:{outage['outageId']}"
            utility = names.get(outage['utilityId']) or f"Utility {outage['utilityId']}"
            out = 'unknown' if outage['customersOut'] is None else f"{outage['customersOut']:,}"
            current[key] = (
                f"{site['name']} ({utility})",
                f"customers out: {out}, cause: {outage['cause'] or 'not reported'}, "
                f"estimated restoration (UTC): {outage['estimatedRestorationAt'] or 'not given'}",
            )

announced = json.loads(STATE_FILE.read_text()) if STATE_FILE.exists() else {}
started = [f'{label}: {details}' for key, (label, details) in current.items() if key not in announced]
ended = [label for key, label in announced.items() if key not in current]
if started:
    notify(f'Power outage at {len(started)} watched site(s)', started)
if ended:
    notify(f'Outage no longer reported at {len(ended)} site(s)', ended)
# Saved only after every post succeeded, so a failed post is repeated on the next run.
STATE_FILE.write_text(json.dumps({key: label for key, (label, _) in current.items()}))

Step 5: Check what each platform receives

These are the two request bodies for one site. Workflows webhooks accept Adaptive Cards in this message envelope and reject requests over 28 KB, which is why the poller lists at most 40 sites per message and adds a count of the rest. Teams throttles more than four requests a second to one webhook and Slack allows about one message a second per channel; the poller sends at most two messages per run to each.

json
Slack (incoming webhook)
{"text": "*Power outage at 1 watched site(s)*\nStore 214, Savannah (Georgia Power): customers out: 1,240, cause: Tree on line, estimated restoration (UTC): 2026-12-03T21:30:00.000Z"}

Microsoft Teams (Workflows webhook)
{
  "type": "message",
  "attachments": [{
    "contentType": "application/vnd.microsoft.card.adaptive",
    "content": {
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "type": "AdaptiveCard",
      "version": "1.2",
      "body": [
        {"type": "TextBlock", "text": "Power outage at 1 watched site(s)", "weight": "Bolder", "wrap": true},
        {"type": "TextBlock", "text": "Store 214, Savannah (Georgia Power): customers out: 1,240, ...", "wrap": true}
      ]
    }
  }]
}

Step 6: Run it every 15 minutes

Keep the API key and both webhook URLs in an environment file that only the job's account can read, and run the poller from that account's crontab. The shell reads the file, so keep every value in single quotes, as shown. A Teams Workflows URL contains &, which an unquoted value would turn into a background command. flock -n stops two runs from editing the state file at once. Every 15 minutes is enough for most sites. The data updates every minute, so for the latest answers run it every 1 or 2 minutes (* * * * * or */2 * * * *). The first run announces every site that is already inside an outage.

text
# /opt/poweroutage/chat.env: owned by the account that runs the job, chmod 600.
# Put every value in single quotes, as below; write a single quote inside a value as '\''.
POWEROUTAGE_API_KEY='...'
SLACK_WEBHOOK_URL='https://hooks.slack.com/services/...'
TEAMS_WEBHOOK_URL='...'
SITES_FILE='/opt/poweroutage/sites.json'
STATE_FILE='/opt/poweroutage/chat-announced.json'

# crontab -e, as that account. flock skips a run if the previous one is still going.
*/15 * * * * set -a && . /opt/poweroutage/chat.env && flock -n /opt/poweroutage/chat.lock /usr/bin/python3 /opt/poweroutage/poweroutage_chat.py >> /opt/poweroutage/poweroutage_chat.log 2>&1

Tips for Slack and Microsoft Teams

  • Keep the state file between runs. If it is lost, the next run announces every current outage again and never posts the all-clear for outages that ended in between. On a serverless scheduler, keep it in object storage instead of on local disk.
  • A site whose utilities all report providesGeospatialData: false is never announced, because those utilities publish counts by area only. Check the utilities list in the response to see which sites are affected.
  • Utilities sometimes report overlapping outages, so one site can be announced twice with two different utilities or outage ids.
  • Post to a dedicated alerts channel. To page someone instead of posting, see the PagerDuty guide, which uses the same check with trigger and resolve events.

Used by

Related integrations

FAQ

Here are some commonly asked questions

Request API access

Tell us what you're building and we'll set you up with a trial key.