Approved, not published yet. Visible on the preview site only.

Turn a smart bulb into a status light for long jobs

Blue when a job needs you, green when it is done, red when it failed. How we turned a colour bulb into a calm status light, with Claude Code as the trigger.

Automation8 min read

A table lamp beside a closed laptop and a small potted plant on a wooden desk

You start a long job, a build, a backup or an AI coding assistant working through a task, and go to make tea. You come back to find it stopped after two minutes to ask a question, and has been waiting ever since.

We fixed this with one of the cheapest smart devices you can buy: a colour bulb in a desk lamp. When a long job needs us, the lamp breathes blue. When it finishes, green. When it fails, red. Then it goes back to exactly what it was doing before.

Our trigger is Claude Code, the AI coding tool we use. The same pattern works for a 3D printer, a washing machine or anything else that finishes on its own schedule.

Why a light and not a notification

Notifications pile up unread, and a sound interrupts everyone. A colour change in the corner of your eye needs no reading.

When not to bother:

  • You cannot see the lamp from where you wait. A status light in another room is just a light.
  • Your jobs take under a minute. You will be looking at the screen anyway.
  • You need a record. A light leaves no trace, so send a proper alert as well.

The colour scheme and the pulse

Three colours, no more: blue means something needs an answer from you, green means a job finished, red means it failed. Blue sits furthest from warm white, so it is the easiest to spot.

We wanted a tap on the shoulder, not an alarm:

  • Switch to the colour at full brightness.
  • Do three slow breaths of about three seconds each, fading down to roughly 1 percent and back on a smooth curve.
  • Never go fully off mid pulse. Off and back looks like a strobe.
  • Then restore the lamp exactly as it was: on or off, white or colour, same tone, same brightness.

The restore step is the one people skip, and the one that makes this livable.

One slow blue breath on the lamp, fading to a dim glow and back, then returning to warm white
One slow blue breath on the lamp, fading to a dim glow and back, then returning to warm white

What you need

  • A Wi-Fi or Zigbee colour bulb in a lamp you can see from your desk. Wi-Fi colour bulbs run about ₹500 to ₹1,200; Zigbee ones about ₹1,000 to ₹2,500, plus a Zigbee USB stick of about ₹2,000 to ₹4,000 if you do not have one. Ours is a Tuya based RGB plus white E27 bulb.
  • A desk lamp with an E27 holder, about ₹500 to ₹2,000.
  • Home Assistant, or any hub with an API, on a machine that stays on. A small single board computer or used mini PC is roughly ₹5,000 to ₹15,000.
  • A small script that saves the bulb's state, pulses and restores.
  • A trigger. For us, Claude Code hooks. For you, maybe a build script or an automation.

The bulb screws into an ordinary lamp, so there is no wiring. A fixed ceiling fitting is a job for a licensed electrician.

How to build it

  1. Pair the bulb in the Smart Life or Tuya app so it is on your Wi-Fi. You see it respond to the app.

  2. Move it to local control. Cloud bulbs send every command out to the maker's server and back, which is too slow for a smooth breath. They also stop responding when the internet does.

  3. Fetch the local key with the community integration Tuya Local:

    • Install Tuya Local through HACS.
    • Go to Settings, Devices and services, Add integration, Tuya Local.
    • Sign in by scanning the QR code with the Smart Life app.
    • Pick the bulb, and it fills in the device ID, address and key. Choose the matching profile and protocol version if asked.
    • Keep the bulb and the hub on the same network.
    • Ours was added by hand with the key fetched separately; the result is the same.

    When it works, the light toggles in a fraction of a second with the internet unplugged.

  4. Lock it down. Give the bulb a DHCP reservation so its address never changes, and turn off firmware auto-update in the app. You see the same address on the router's client list after a reboot.

  5. Make a token. In Home Assistant click your name bottom left, Security, Long-lived access tokens, Create token. Save it to a file such as ~/.config/lamp/token and run chmod 600 on it. Never put it in the script or in anything that might reach a repository.

  6. Write the script. It takes a colour, snapshots the lamp, pulses, and restores. Run it by hand with done and the lamp breathes green three times, then returns to what it was.

  7. Attach the trigger. For Claude Code, add hooks (below). Finish a reply, wait, and the lamp tells you.

With a Zigbee bulb, skip the local key and address steps. Pair it through Zigbee2MQTT or ZHA and it is already local, with no key to fetch and no address to reserve.

The script wraps two Home Assistant REST calls with an Authorization: Bearer [token] header read from the token file: GET /api/states/[entity] for the snapshot, POST /api/services/light/turn_on (or turn_off) for the pulse and restore. The core of our script, trimmed, with placeholders:

import json, math, sys, time, urllib.request

HA, ENTITY = "http://YOUR-HUB-ADDRESS", "light.example_lamp"
TOKEN = open("/path/to/token").read().strip()
COLOURS = {"attention": [225, 100], "done": [120, 100], "error": [0, 100]}  # hue, saturation
PULSES, PULSE_SECONDS, MIN_BRIGHTNESS = 3, 3.0, 3   # 3 of 255 is about 1 percent
kind = sys.argv[1]

def ha(path, body=None):
    req = urllib.request.Request(HA + path, data=json.dumps(body).encode() if body else None,
        headers={"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=5) as r:   # POST when there is a body
        return json.load(r)

def call(service, **data):
    ha(f"/api/services/light/{service}", {"entity_id": ENTITY, **data})

def snapshot():
    s = ha(f"/api/states/{ENTITY}")
    a = s["attributes"]
    snap = {"on": s["state"] == "on", "brightness": a.get("brightness")}
    if a.get("color_mode") == "color_temp":
        snap["color_temp_kelvin"] = a.get("color_temp_kelvin")
    else:
        snap["hs_color"] = a.get("hs_color")
    return snap

def restore(snap):
    on = snap.pop("on")
    call("turn_on", **{k: v for k, v in snap.items() if v is not None}) if on else call("turn_off")

def pulse(kind):
    call("turn_on", hs_color=COLOURS[kind], brightness=255)
    time.sleep(0.6)                                  # let the colour land
    t0 = time.monotonic()
    while (t := time.monotonic()-t0) < PULSES * PULSE_SECONDS:
        level = (1 + math.cos(2 * math.pi * t / PULSE_SECONDS)) / 2   # 1, down to 0, back to 1
        call("turn_on", brightness=round(MIN_BRIGHTNESS + level * 252))
        time.sleep(0.1)

snap = snapshot()
try:
    pulse(kind)
finally:
    restore(snap)

The loop asks for ten steps a second. On local control each command takes roughly 200 to 400 ms, so the lamp really gets a few steps a second, enough for a soft fade.

The full version retries the restore in that finally block, so the lamp goes back to normal even if a pulse fails. A lock file keeps it to one signal at a time, and a log records every decision, including skips.

The Claude Code hooks

Claude Code can run a command when certain events happen. We use three: Notification, filtered to permission prompts and tool-driven input dialogs (blue); Stop, when a reply finishes (green); and StopFailure, when a reply ends in an error (red).

{
  "hooks": {
    "Notification": [
      { "matcher": "permission_prompt|elicitation_dialog",
        "hooks": [{ "type": "command", "command": "/path/to/lamp-signal attention", "timeout": 5 }] }
    ],
    "Stop": [
      { "hooks": [{ "type": "command", "command": "/path/to/lamp-signal done", "timeout": 5 }] }
    ],
    "StopFailure": [
      { "hooks": [{ "type": "command", "command": "/path/to/lamp-signal error", "timeout": 5 }] }
    ]
  }
}

The JSON goes in ~/.claude/settings.json for every project, or .claude/settings.json inside one project. Type /hooks inside Claude Code to confirm the three entries loaded. Back up the settings file first, so removing the hooks is a one line copy.

Three hooks in a settings file, each calling the same lamp script with a different signal
Three hooks in a settings file, each calling the same lamp script with a different signal

The five minute rule

Firing instantly is a common mistake: at the desk, you already know. So every signal waits five minutes. Claude Code hands the hook the path to the session's transcript file, so the check is simple: has that file changed since? If you replied or the assistant carried on, it has, and the signal is cancelled. The lamp only speaks up when you have actually walked away.

The hook must hand off and exit at once. Ours starts the timer as a detached copy of itself with subprocess.Popen(..., start_new_session=True); from a shell, setsid lamp-signal --wait attention & does the same job. The 5 second hook timeout then only covers writing the marker, which is why it is safe.

The marker is a small file per session in a cache directory, holding a unique value for that signal. A few seconds after the hook fires, the timer notes the transcript's size and modified time. When the timer ends, if the marker still holds its value and the transcript has not changed, the pulse runs; otherwise nothing happens. The delay is a config value. A newer signal replaces an older one, and blue may interrupt green or red, because "I need you" outranks "I'm done".

How a signal travels: hook fires, five minute wait, check for activity, then pulse and restore or cancel
How a signal travels: hook fires, five minute wait, check for activity, then pulse and restore or cancel

What goes wrong

  • Bulb goes unavailable after re-pairing. Removing and re-adding it in the app gives it a new local key. Fetch the key again and update Tuya Local.
  • Bulb disappears after a router restart. Its address changed. Add the DHCP reservation.
  • Local control breaks one morning. A firmware update changed the protocol. Try the other protocol versions in Tuya Local.
  • Warm white comes back slightly orange. You saved the colour but not the colour mode. Save colour temperature for white mode and hue for colour mode.
  • Every signal cancels itself. The session is still writing when the hook fires. Wait a few seconds before noting the transcript's baseline.
  • Blue straight after every green. You hooked the "idle for a while" notification, which fires about a minute after each reply. Leave it out.

Other jobs, same lamp

The script does not care what calls it. After a build: make && lamp-signal done || lamp-signal error. For a washing machine, use a power monitoring smart plug and treat "a few watts for a few minutes" as finished. An uptime monitor's "down" alert can turn it red.

Cost and time

If you already run Home Assistant, the bulb is the only purchase, roughly ₹500 to ₹1,200. Allow an evening. Starting from nothing: bulb, lamp and a single board computer or used mini PC come to roughly ₹6,000 to ₹18,000, approximate and varying by seller, and allow a weekend.

The short version

A colour bulb on local control, three colours, a gentle pulse that never goes dark, a delay that cancels when you are busy, and a restore every time. Done well, nobody notices the lamp is smart. It just occasionally, politely, tells you to come back.

TDH Systems builds small automations like this for homes and offices. See what we automate.

Written by Siddharth Agrawal, Founder and Director, TDH Systems.

Tell us what you have in mind. We will come back with a plan and a quote.

Start a project

Prefer email? Write to info@thydarkhour.com.