No description
  • Python 99.4%
  • Shell 0.6%
Find a file
Djuri Baars d26d268136
Some checks failed
Lint / Ruff (push) Failing after 4s
Test / Pytest (push) Failing after 1m9s
Validate / Hassfest Validation (push) Failing after 2s
Validate / HACS Validation (push) Failing after 1m8s
Release / Release (release) Failing after 1m8s
Reload config entry after a successful OTA
Entity composition is decided at setup time based on the detected API
variant (legacy vs 3.4.0+): currency select, DND switch, screen nav
buttons, etc. are only added on V3.4. When a device updates across that
boundary, the previously-set-up entities become stale — V3.4-only ones
show as unavailable on a downgrade, and new-only-on-V3.4 entities never
appear on an upgrade. Reported on btclock-2ad158 after an update.

The install watchdog now schedules a config-entry reload as soon as it
confirms a gitTag change, so async_setup_entry re-runs with the new
variant and entities match the device's current capabilities. The reload
is fired as a detached task — calling it synchronously from inside the
watchdog's finally would cancel this very task (the Update entity is
about to be unloaded).

Reload is skipped on timeout: if the device never came back, thrashing
entities doesn't help anyone.
2026-04-18 17:48:14 +02:00
.github ci(release): fix workflow to reference the btclock integration 2026-04-18 10:49:44 +02:00
.vscode Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00
config Initial commit 2023-11-18 21:47:32 +00:00
custom_components/btclock Reload config entry after a successful OTA 2026-04-18 17:48:14 +02:00
scripts Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00
tests Reload config entry after a successful OTA 2026-04-18 17:48:14 +02:00
.devcontainer.json Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00
.gitattributes Initial commit 2023-11-13 20:09:19 +01:00
.gitignore Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00
.ruff.toml Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00
CONTRIBUTING.md Initial commit 2023-11-13 20:09:19 +01:00
hacs.json Revert "hacs: allow installing the main branch alongside tagged releases" 2026-04-18 11:25:18 +02:00
LICENSE Create README 2023-11-19 00:20:24 +01:00
pyproject.toml Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00
README.md Add custom-text services, LED brightness/disable, and firmware updates 2026-04-18 13:49:43 +02:00
requirements.txt Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00
requirements_test.txt Rewrite for BTClock firmware 3.4.0 and modernize HA integration 2026-04-18 10:43:16 +02:00

BTClock Integration

License: MIT

Home Assistant integration for the BTClock — an open-source Bitcoin price / block-height display.

Open in HACS Add integration

Supported firmware

Firmware Status Notes
3.4.0+ Full POST-style API, SSE push updates, HTTP auth, DND, frontlight
3.3.x and earlier Basic GET-style API; read-only DND and no frontlight controls

The variant is detected automatically from GET /api/settings.

Platforms

Platform Entities
sensor Current screen, currency, uptime, RSSI, free heap, ambient light level
binary_sensor Price / blocks / V2 / nostr feed connectivity, screen timer, OTA, DND
switch Screen timer, Do-not-disturb (3.4.0+)
select Screen, currency (3.4.0+)
light One entity per status LED, plus frontlight (when hardware present)
number LED brightness slider (0255)
button Identify, restart, full refresh, next / previous screen, flash frontlight (3.4.0+)
update Firmware update (auto-update or specific version, 3.4.0+ release builds)

Services

Service Purpose
btclock.show_text Display a string across the device's screens (one char each, auto-uppercased, clamped to numScreens)
btclock.show_custom Display one string per screen — handy for symbols or multi-char labels

Firmware updates

If the BTClock is running a real release (e.g. 3.3.19, not a commit-hash dev build), the integration polls its configured gitReleaseUrl once a day and surfaces a firmware update entity — it also shows up in Settings → Updates. Release notes default to the release body; when that's empty, they're synthesized from the first-line commit messages of the compare API between the installed and latest tags.

Installing the latest version fires POST /api/firmware/auto_update and lets the device download + flash itself. Installing an older version downloads the matching {board}_firmware.bin and littlefs_{size}.bin assets and uploads them to /upload/firmware and /upload/webui; the device reboots into the new image at the end.

Data-source sensors

connectionStatus exposes four separate feeds — price, blocks, V2, nostr — because a BTClock can be driven by any combination of them depending on its dataSource setting. The integration exposes a binary sensor per feed:

  • Price / Blocks feed — always enabled by default (the common case — BTClock driven by the built-in mempool source).
  • V2 / Nostr feed — hidden by default, but auto-enabled at integration setup if the feed is already connected. If you later switch the device's dataSource, toggle the sensor visibility manually in Home Assistant's entity registry or reconfigure the integration.

Live updates

During setup you pick one of two strategies; swap later via Settings → Devices & Services → BTClock → Configure.

  • Server-Sent Events (default) — the integration subscribes to the BTClock's /events stream and receives status pushes the moment they happen. Lowest latency, zero polling traffic. The SSE client auto-reconnects with jittered backoff if the connection drops.
  • Polling — plain periodic GET /api/status. Choose this if SSE is unreliable on your network (e.g. through a flaky reverse proxy or VPN). The scan interval is configurable (5 3600 seconds, default 30).

HTTP Basic Auth

If the BTClock has httpAuthEnabled turned on, the config flow will prompt for credentials. When credentials stop working (e.g. you rotated the password on the device), Home Assistant will surface a reauth prompt.

Installation via HACS

HACS currently only accepts GitHub repositories, so use the GitHub mirror — the git.btclock.dev Forgejo instance won't work.

  1. Open in HACS — or manually: HACS → Integrations → menu → Custom repositories → add https://github.com/dsbaars/homeassistant-btclock with category Integration.
  2. Install "BTClock Integration" and restart Home Assistant.
  3. Add integration — or Settings → Devices & Services → Add Integration → BTClock, or accept the auto-discovered zeroconf prompt.

Manual installation

  1. Copy custom_components/btclock/ into your Home Assistant configuration's custom_components/ directory.
  2. Restart Home Assistant.
  3. Add the integration from Settings → Devices & Services.

Development

See CONTRIBUTING.md. Recommended workflow is to use the VSCode Dev Container (.devcontainer.json ships Python 3.13 + HA latest + test deps). Useful scripts:

  • scripts/setup install runtime + test deps
  • scripts/test run pytest tests/
  • scripts/check ruff lint + format check + pytest
  • scripts/develop boot a debug Home Assistant on port 8123 with this integration loaded (set BTCLOCK_DEBUGPY=1 to attach on port 5678)

Contributing

Issues and pull requests welcome at https://git.btclock.dev/btclock/homeassistant-btclock or the GitHub mirror.