Skip to content

Home Assistant over MQTT: each array as a device with sensors and buttons - #33

Merged
firsttris merged 1 commit into
masterfrom
claude/home-assistant
Oct 9, 2026
Merged

firsttris merged 1 commit into
masterfrom
claude/home-assistant

Conversation

@firsttris

Copy link
Copy Markdown
Owner

Each array becomes a device in Home Assistant through MQTT discovery. Home Assistant's own MQTT integration picks the entities up, so there is no custom integration to install.

Entities per array (device SnapRAID <name>)

  • Health (ok, errors, disk_missing, sync_incomplete, unknown)
  • Problem (binary sensor, class problem) and Job running (binary sensor, class running)
  • Bad blocks, Last sync and Last scrub (timestamps), Scrubbed (%)
  • Per disk: temperature (°C) and used (%)
  • Buttons: Sync and Scrub
    • A sync from Home Assistant goes through the sync guard of new schedules (50 deleted, 100 changed files).
    • When the guard stops it, the usual skipped notification explains why. Nothing starts while another job runs.

How

  • Shared data source: the data comes from the same cached snapshot as the Prometheus metrics, so publishing never wakes a disk. That collection moved from the metrics route into array-snapshot.ts, which both now use.
  • When it publishes:
    • State is retained and sent when it changes. Jobs are checked every 5 seconds, using the current job and the end time of the last one, so short jobs between two checks are caught too. Everything else every 30 seconds, and the full set at least every 5 minutes.
    • snapraid-ui/status reports online/offline through the MQTT last will, so the entities turn unavailable when SnapRAID UI is down.
    • Discovery is sent again when Home Assistant restarts (homeassistant/status). Entities of removed arrays are cleared.
  • Code layout:
    • home-assistant.ts: pure functions (slugs, state, discovery, command parsing).
    • home-assistant-service.ts: MQTT connection and settings, using npm:mqtt.
    • routes/home-assistant.ts: GET/PUT settings with the password masked; settings are stored in home-assistant.json with mode 600. Plus POST /test.
  • UI: a card under Automation with broker, credentials, discovery prefix and topic, Test connection, and a Connected / Not connected badge.
  • Backup: home-assistant.json is now part of the backup. The docs table also lists the automation files.

Tests

  • Backend: 143 passed, checked with Deno 2.5 (the CI version) and 2.9. New tests:
    • slugs
    • state (health, runs, disks, running job)
    • discovery payloads
    • command parsing
    • settings: masking, address check, topics
  • Frontend: Biome, typecheck, Vitest.
  • E2E: 16/16 locally. The new home-assistant.spec.ts starts an MQTT broker (aedes) in the test, sets Home Assistant up in the UI, checks that discovery and state arrive, and presses the Scrub and Sync buttons over MQTT.
  • Docs: Home Assistant section in automation.md (entities, guard, example automation), API rows in architecture.md, development.md, disks.md (backup), README. mkdocs build --strict passes.

This PR, #31 and #32 each add translation keys and a row to the E2E table in development.md. Whichever merges later needs a rebase; I'll do it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JuXnquCPdbG5sBbDyin7yF


Generated by Claude Code

@firsttris
firsttris force-pushed the claude/home-assistant branch from 287af4d to e21699b Compare October 9, 2026 11:19
…tons

MQTT discovery makes every array a device in Home Assistant: health,
problem and job-running binary sensors, bad blocks, last sync and scrub,
scrubbed share, temperature and fill level per disk, and buttons for
sync and scrub. A sync from Home Assistant goes through the sync guard
of new schedules. State comes from the same cached snapshot as the
Prometheus metrics (now shared in array-snapshot.ts), so publishing
never wakes a disk; it is sent on change, with a last will for
availability, and discovery again when Home Assistant restarts.

Set up under Automation, with a connection test. With unit and
end-to-end tests (MQTT broker in the test) and documentation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JuXnquCPdbG5sBbDyin7yF
@firsttris
firsttris force-pushed the claude/home-assistant branch from e21699b to 772bd15 Compare October 9, 2026 11:22
@firsttris
firsttris merged commit fe07018 into master Oct 9, 2026
4 checks passed
@firsttris
firsttris deleted the claude/home-assistant branch October 16, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants