Skip to content

Turn a ~$5 AliExpress clock into a physical AI usage dashboard (Claude, Codex, multi-account). No firmware flashing.

Serve /watch.json for Apple Watch complication apps

click6067-ship-itf55b4da0b9fe
diff --git a/README.ko.md b/README.ko.md
index f39a8b7..689dc0f 100644
--- a/README.ko.md
+++ b/README.ko.md
@@ -7,7 +7,7 @@
**구경하기:** [라이브 데모](https://token-tv.vercel.app) 또는 `npx github:click6067-ship-it/token-tv demo`, 시계·로그인 없이 바로.
**설치하기:** 이 저장소를 AI에게 주고 *"TokenTV 설정해줘"* 라고 하세요. AI는 [AGENTS.md](AGENTS.md)를 따릅니다.
**내 화면 만들기:** 시계 없이 [Game Boy 예제](examples/gameboy)에서 시작해 AI에게 바꿔 달라고 하세요. [가이드](docs/clock-faces.md) · [공유하기](https://github.com/click6067-ship-it/token-tv/issues/new?template=share_a_face.md)
-자세히: [설정](docs/setup.ko.md) · [호환 시계](docs/hardware-compatibility.md) · [CodexBar 연동](docs/codexbar.md) · MIT · [English](README.md)
+자세히: [설정](docs/setup.ko.md) · [호환 시계](docs/hardware-compatibility.md) · [CodexBar 연동](docs/codexbar.md) · [애플워치](docs/apple-watch.md) · MIT · [English](README.md)
[Hackaday에 소개됐습니다](https://hackaday.com/2026/10/06/smalltv-hacking-with-surprisingly-little-fuss/).
<p align="center"><a href="examples/gameboy"><img src="examples/gameboy/comparison.png" width="640" alt="내 화면 만들기: 같은 샘플 사용량으로 그린 원래 픽셀 화면과 4색 Game Boy 예제"></a></p>
diff --git a/README.md b/README.md
index dc4c3f3..77f6514 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Your Claude and Codex usage limits on a ~$5 Wi-Fi desk clock. No firmware flashi
**Try it:** [live demo](https://token-tv.vercel.app) or `npx github:click6067-ship-it/token-tv demo`, no clock or login needed.
**Set it up:** give this repo to your AI and say *"Set up TokenTV for me."* It follows [AGENTS.md](AGENTS.md).
**Make your own face:** no clock needed, start from the [Game Boy example](examples/gameboy) and ask your AI to change it. [Guide](docs/clock-faces.md) · [Share it](https://github.com/click6067-ship-it/token-tv/issues/new?template=share_a_face.md)
-Details: [how it works](docs/stock-photo-display.md) · [setup](docs/setup.md) · [compatible clocks](docs/hardware-compatibility.md) · [CodexBar input](docs/codexbar.md) · MIT · [한국어](README.ko.md)
+Details: [how it works](docs/stock-photo-display.md) · [setup](docs/setup.md) · [compatible clocks](docs/hardware-compatibility.md) · [CodexBar input](docs/codexbar.md) · [Apple Watch](docs/apple-watch.md) · MIT · [한국어](README.ko.md)
Featured on [Hackaday](https://hackaday.com/2026/10/06/smalltv-hacking-with-surprisingly-little-fuss/).
<p align="center"><a href="examples/gameboy"><img src="examples/gameboy/comparison.png" width="640" alt="Change a face: original pixel style and a four-colour Game Boy example, rendered from the same sample readings"></a></p>
diff --git a/docs/apple-watch.md b/docs/apple-watch.md
new file mode 100644
index 0000000..dba4932
--- /dev/null
+++ b/docs/apple-watch.md
@@ -0,0 +1,73 @@
+# Apple Watch complication
+
+The ~$5 clock stays the live display. If you also want a number on your wrist, the computer that
+already runs TokenTV serves a small JSON file, `/watch.json`, and a JSON complication app on the
+iPhone and Apple Watch shows one value from it. No TokenTV app, no extra login on the phone.
+
+## What has been checked
+
+- `/watch.json` on a Linux host with seven real accounts (2026-10-12): every account gets the same
+ number, window and OLD / NO DATA state the clock shows.
+- Not checked yet: a real Apple Watch, and which complication apps accept a plain `http://` address.
+
+## 1. Let the phone reach the computer
+
+TokenTV listens on `127.0.0.1` unless you tell it otherwise. Start it on your home network address:
+
+```bash
+token-tv run --host 0.0.0.0 # or the computer's LAN IP, e.g. --host 192.168.0.20
+```
+
+On the iPhone, on the same Wi-Fi, open `http://<computer-ip>:8787/watch.json` in Safari. You should
+see JSON like the sample below. Anyone on that network can also open the dashboard and switch the
+clock face, so do not forward this port to the internet.
+
+## 2. Add the complication
+
+Install a free app that turns a JSON URL into a complication, for example
+[Complicator](https://apps.apple.com/us/app/-/id6758154567) or
+[ComplicaJSON](https://www.complicajson.com/). Add a data source with:
+
+- URL: `http://<computer-ip>:8787/watch.json`
+- JSON path: `accounts.claude_a.used_percent` (a number), `accounts.claude_a.used` (0–1, for a
+ gauge) or `accounts.claude_a.text` (`44% WK`)
+
+Then add the app's complication to a watch face. watchOS decides how often complications refresh,
+usually every 15–30 minutes, so the watch lags the clock.
+
+## Fields
+
+Accounts are keyed by the name the clock shows: `CLAUDE A` is `claude_a`, `CODEX B` is `codex_b`.
+Config keys are not included.
+
+```json
+{
+ "updated_at": 1791803649,
+ "summary": "CLAUDE A 44% WK · CODEX A 12% 5H OLD · GROK A NO DATA",
+ "accounts": {
+ "claude_a": {"label": "CLAUDE A", "used_percent": 44, "used": 0.44, "window": "WK",
+ "resets_in": "1d 2h", "resets_at": 1791897249, "text": "44% WK", "state": "ok"},
+ "codex_a": {"label": "CODEX A", "used_percent": 12, "used": 0.12, "window": "5H",
+ "resets_in": "1h 0m", "resets_at": 1791807249, "text": "12% 5H OLD", "state": "old"},
+ "grok_a": {"label": "GROK A", "used_percent": null, "used": null, "window": null,
+ "resets_in": "--", "resets_at": null, "text": "NO DATA", "state": "missing"}
+ }
+}
+```
+
+| Field | Meaning |
+|---|---|
+| `used_percent` | Used share of the tightest window, 0–100. `null` when nothing was reported, never 0 |
+| `used` | The same as 0–1, for gauge complications |
+| `window` | `5H`, `WK` or `BUD`, as on the clock |
+| `resets_in`, `resets_at` | Time left as text (computed when the watch asks), and the reset as a Unix time |
+| `text` | What the clock row says, e.g. `44% WK` or `NO DATA` |
+| `state` | `ok`, `old` (the last good value; the latest check failed) or `missing` |
+| `summary` | Every account on one line |
+
+## Away from home
+
+The watch can only reach the address while it is on the same network as the computer. TokenTV does
+not upload your usage anywhere. If you want the number outside, put the computer and the phone on a
+private network you already trust (a VPN such as Tailscale) and use that address; this has not been
+checked with a watch yet.
diff --git a/tests/test_watch.py b/tests/test_watch.py
new file mode 100644
index 0000000..c5e16aa
--- /dev/null
+++ b/tests/test_watch.py
@@ -0,0 +1,67 @@
+import json
+import threading
+import time
+import unittest
+from http.server import ThreadingHTTPServer
+from urllib.request import urlopen
+
+from token_tv.display import watch_payload
+from token_tv.live import handler
+from token_tv.state import UsageStore
+
+
+def row(provider, alias, status='ok', windows=()):
+ return {'provider': provider, 'alias': alias, 'status': status, 'windows': list(windows)}
+
+
+class WatchPayloadTest(unittest.TestCase):
+ def test_fresh_old_and_missing_readings_match_the_clock(self):
+ now = time.time()
+ data = watch_payload({'updated_at': 1000, 'accounts': {
+ 'claude_a': row('claude', 'CLAUDE A', windows=[
+ {'label': '5H', 'used_percent': 10, 'resets_at': now + 3600},
+ {'label': 'WEEK', 'used_percent': 44.4, 'resets_at': now + 26 * 3600 + 30}]),
+ 'codex_a': row('codex', 'CODEX A', 'stale', [{'label': '5H', 'used_percent': 12, 'resets_at': now + 3600}]),
+ 'grok_a': row('grok', 'GROK A', 'quota_unavailable'),
+ }})
+ claude, codex, grok = (data['accounts'][key] for key in ('claude_a', 'codex_a', 'grok_a'))
+ # The tightest window is the one shown, as on the clock.
+ self.assertEqual(claude, {'label': 'CLAUDE A', 'used_percent': 44, 'used': 0.44, 'window': 'WK',
+ 'resets_in': '1d 2h', 'resets_at': round(now + 26 * 3600 + 30),
+ 'text': '44% WK', 'state': 'ok'})
+ self.assertEqual((codex['state'], codex['text']), ('old', '12% 5H OLD'))
+ # Missing stays missing: never 0%.
+ self.assertEqual((grok['used_percent'], grok['used'], grok['window'], grok['state'], grok['text'],
+ grok['resets_in']), (None, None, None, 'missing', 'NO DATA', '--'))
+ self.assertEqual(data['summary'], 'CLAUDE A 44% WK · CODEX A 12% 5H OLD · GROK A NO DATA')
+ self.assertEqual(data['updated_at'], 1000)
+
+ def test_keys_follow_clock_labels_not_config_keys(self):
+ accounts = {'claude_work': row('claude', 'CLAUDE A'), 'claude_friend': row('claude', 'CLAUDE B'),
+ 'claude_x': row('claude', 'Home'), 'claude_y': row('claude', 'Lab')}
+ data = watch_payload({'updated_at': 0, 'accounts': accounts})
+ self.assertEqual(list(data['accounts']), ['claude_a', 'claude_b', 'claude_a_2', 'claude_a_3'])
+ self.assertNotIn('friend', json.dumps(data))
+
+ def test_no_accounts_says_so(self):
+ self.assertEqual(watch_payload({'updated_at': 0, 'accounts': {}}),
+ {'updated_at': 0, 'summary': 'NO ACCOUNTS', 'accounts': {}})
+
+
+class WatchEndpointTest(unittest.TestCase):
+ def test_watch_json_is_served_as_json(self):
+ server = ThreadingHTTPServer(('127.0.0.1', 0), handler(UsageStore([])))
+ thread = threading.Thread(target=server.serve_forever)
+ thread.start()
+ try:
+ with urlopen(f'http://127.0.0.1:{server.server_port}/watch.json') as response:
+ self.assertTrue(response.headers['Content-Type'].startswith('application/json'))
+ self.assertEqual(json.load(response)['summary'], 'NO ACCOUNTS')
+ finally:
+ server.shutdown()
+ server.server_close()
+ thread.join()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/token_tv/display.py b/token_tv/display.py
index 6a21ced..fa0e7ba 100644
--- a/token_tv/display.py
+++ b/token_tv/display.py
@@ -134,6 +134,40 @@ def quota_period(value):
return {'WEEK': 'WK', 'BUDGET': 'BUD'}.get(value['label'], value['label'])
+def reading(row):
+ """(used %, window label, old?, time left) for one account; used is None when nothing was reported."""
+ value = primary_window(row)
+ used = max(0, min(100, value['used_percent'])) if value else None
+ period = quota_period(value) if value else STATUS.get(row['status'], 'NO DATA')
+ old = bool(value) and row['status'] != 'ok'
+ reset = time_left(value.get('resets_at')) if value else '--'
+ return used, period, old, reset
+
+
+def watch_payload(snapshot):
+ """Flat JSON for Apple Watch complication apps that read one value by path, e.g. accounts.claude_a.used_percent.
+
+ Accounts are keyed by the label the clock shows (CLAUDE A -> claude_a), not by config keys, which can say
+ whose account it is."""
+ accounts, parts = {}, []
+ for row in snapshot['accounts'].values():
+ key = base = account_label(row).lower().replace(' ', '_')
+ number = 1
+ while key in accounts:
+ number += 1
+ key = f'{base}_{number}'
+ used, period, old, reset = reading(row)
+ used = None if used is None else round(used)
+ value = primary_window(row)
+ text = period if used is None else f'{used}% {period}' + (' OLD' if old else '')
+ accounts[key] = {'label': account_label(row), 'used_percent': used,
+ 'used': None if used is None else used / 100, 'window': None if used is None else period,
+ 'resets_in': reset, 'resets_at': round(value['resets_at']) if value and value.get('resets_at') else None,
+ 'text': text, 'state': 'missing' if used is None else 'old' if old else 'ok'}
+ parts.append(f'{account_label(row)} {text}')
+ return {'updated_at': snapshot['updated_at'], 'summary': ' · '.join(parts) or 'NO ACCOUNTS', 'accounts': accounts}
+
+
# A code-native 5×7 alphabet keeps LCD text on a visible pixel grid.
PIXEL_GLYPHS = {
'A': '01110/10001/10001/11111/10001/10001/10001',
diff --git a/token_tv/live.py b/token_tv/live.py
index c31612c..ea1e119 100644
--- a/token_tv/live.py
+++ b/token_tv/live.py
@@ -11,7 +11,7 @@ from urllib.parse import parse_qs, urlparse
from token_tv.device import FILES, BackupMismatch, open_display
from token_tv.catalog import payload as theme_payload
-from token_tv.display import STYLES, render_page
+from token_tv.display import STYLES, render_page, watch_payload
from token_tv.web_assets import HTML, ASSETS, asset
from token_tv.sources import load_config
from token_tv.state import UsageStore
@@ -108,6 +108,8 @@ def handler(store, preferences=None):
body = json.dumps(theme_payload()).encode()
elif path == '/display':
body = json.dumps(display).encode()
+ elif path == "/watch.json":
+ body = json.dumps(watch_payload(snapshot), ensure_ascii=False, separators=(",", ":")).encode()
elif path == "/health":
body = json.dumps({"status": "ok", "updated_at": snapshot["updated_at"]}).encode()
else:
diff --git a/token_tv/themes.py b/token_tv/themes.py
index 555eb3a..8d5f4a9 100644
--- a/token_tv/themes.py
+++ b/token_tv/themes.py
@@ -12,7 +12,7 @@ from pathlib import Path
from PIL import Image, ImageDraw, ImageFilter, ImageFont
from token_tv.display import (
- PROVIDER_INK, STATUS, account_label, mascot, overview_rows, primary_window, quota_period, row_shift, time_left,
+ PROVIDER_INK, account_label, mascot, overview_rows, reading, row_shift,
)
WEB = Path(__file__).with_name('web')
@@ -63,15 +63,6 @@ def band(theme, used):
return BANDS[theme][0 if used < 50 else 1 if used < 80 else 2 if used < 90 else 3]
-def reading(row):
- value = primary_window(row)
- used = max(0, min(100, value['used_percent'])) if value else None
- period = quota_period(value) if value else STATUS.get(row['status'], 'NO DATA')
- old = bool(value) and row['status'] != 'ok'
- reset = time_left(value.get('resets_at')) if value else '--'
- return used, period, old, reset
-
-
def ghost(text):
"""Unlit seven-segment cells: every lit glyph cell becomes 8."""
return ''.join(c if c in ' :' else '8' for c in text)