I’m using Prometheus to monitor my home office and homelab, I figured it would be cool to have a stack light show the active warnings and alerts from Alertmanager. So I made a HAT (Hardware Attached on Top) for the Raspberry Pi to drive a five-colored stack light.

Table of contents

The build

My stack light has five lights; white, blue, green, orange and red. So I needed five channels, I didn’t want the driver to make any relay clicking sounds, so I a used a Darlington-driver and five Darlington-transistors.

On the backside of the perfboard is a 20-pin female pin-header, to connect to the Raspberry Pi GPIO pins. I’m not using all 20 pins, but it makes the HAT attach firmly to the Pi.

Also on the backside is the Darlington-driver, this is connected to the GPIO pins and drives the five Darlington-transistors.

The Darlington-transistors can handle 5 A, but my stack light has LEDs so the power draw is pretty low. The stack light has a common ground, so I used PNP transistors.

The HAT is connected to 12V which it uses to drive the stack lights.

I used a 6-pin pluggable terminal connector for the common ground and light outputs.

Software

I made a python script to talk to the Alertmanager API and control the GPIO pins:

https://github.com/thomasjsn/stack-light-alertmanager

Operation

Each color can be configured steady true or false:

steady
Flash for one cycle when alarm count is increased, continuous light as long as at lease one alarm is active
not steady
Only flash for one cycle when the alarm count is increased.

One cycle is the wait time between checking the Alertmanager API, this happens every 10 seconds.

Colors

The colors indicate the alarm severity;

severities = {
        'alert': 'red',
        'warn': 'orange',
        'info': 'white'
        }

This can be overridden by assigning a label color to the Prometheus alert rule. The blue color has no default severity, and must be assigned manually.

  - alert: HomelabPowerAlert
    expr: mqtt_alert_state{origin="homelab"} == 1
    labels:
      severity: alert
      color: blue
    annotations:
      summary: "Homelab power alert on {{ $labels.alert }}"

The green color has a special function; every time the alarm count is decreased; the green light flashes for one cycle.

Default color settings

Color Severity Steady
Red Alert
Orange Warning
Green Resolved
Blue -
White Info

The video below shows the startup sequence, followed by an active warning situation.

Homelab

Stack light mounted on homelab rack
Raspberry Pi and HAT on shelf in homelab rack

Power loss

The video below shows what happens in my home office, and on the homelab, during a power loss.

The rotating lights are a function of the stack light itself, the output from the controller is constant.

I/O

Raspberry Pi GPIO pinout

Outputs

  • GPIO 24: Red
  • GPIO 4: Orange
  • GPIO 3: Green
  • GPIO 2: Blue
  • GPIO 17: Clear

Schematic diagram

Schematics for the Raspberry Pi output HAT

Parts used

  • 1 × Raspberry Pi 3 Model B, 1.2GHz Quad 64bit, 1GB RAM, BT, WLAN
  • 1 × Stacklight, light signal, Red/Yellow/Green/Blue/White, LED 12V, 10W
  • 1 × Terminal block, pluggable, 5 mm, 6-pin screw female

HAT

  • 1 × Darlington-driver, 7 step, ULN2003A, DIL16, In: 2.7K/5V
  • 5 × Darlington-transistor, PNP, 5 A, 60V, TIP125, TO-220
  • 1 × DIL socket, 16-pin, 7.62mm
  • 1 × PCB, perfboard prototyping, 50x70mm, 35cm2
  • 5 × Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
  • 10 × Straight pin header, female, Dual row, 2.54mm
  • 1 × Terminal block, pluggable, 5 mm, 6-pin vertical male
  • 1 × Terminal blocks, screw, PCB, 3.5mm, 2-pin, straight

Last commit 2024-04-05, with message: Tag cleanup.