home-assistant

A set of rules for building a Home Assistant integration, covering configuration, asynchronous code, entities, Git operations, and project state. Home Assistant is software for controlling and monitoring smart-home devices.

In plain words
What is it for?
Use it when implementing setup and unload flows, config entries, sensors, buttons, asynchronous Git operations, manifests, requirements, or state management.
Why use it?
It keeps the integration compatible with Home Assistant conventions and avoids blocking its event loop or duplicating configuration details.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/ckrl/ha-gitops/home-assistant
Clone the repo
git clone --depth 1 https://github.com/ckrl/ha-gitops

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,627 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 2 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01627
Opus 5 $0.00000 $0.00813
Sonnet 5 $0.00000 $0.00325
Haiku 4.5 $0.00000 $0.00163

Measured 2d ago against content hash 15cfef29dd1e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

home-assistant scanned grade A with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

async def fetch(self) -> GitResult: ...

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

- Запрещены: `time.sleep`, `subprocess.run`, `requests`, `os.system`, чтение/запись файлов через `open()` без executor.
.cursor/rules/home-assistant.mdc · 89 lines

How it starts

The opening of the file, as written. The whole thing — 89 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Home Assistant Integration Rules

Применяются ко всему коду внутри custom_components/ha_gitops/.

Bootstrap

  • DOMAIN = "ha_gitops" — единственный источник в const.py. Не дублировать литерал.
  • MVP: конфиг через Config Flowasync_setup_entry(hass, entry) + async_unload_entry; manifest.json: config_flow: true. Топовый async_setup(hass, config) только возвращает True (YAML-блок домена не используется).
  • Состояние интеграции — в hass.data[DOMAIN][entry.entry_id] (один config entry на инстанс HA): GitManager и scan_interval.
  • Регистрация платформ: await hass.config_entries.async_forward_entry_setups(entry, ("sensor", "button")).
  • manifest.json — поля строго по docs/architecture.md §5.2: domain, name, version, documentation, issue_tracker, requirements, dependencies, codeowners, iot_class: "cloud_polling", config_flow: true.

Async-контракт

  • Все методы GitManager и все async_* коллбэки HA — async.
  • Любая блокирующая операция — не в event loop: git через GitPython внутри asyncio.to_thread (см. docs/architecture.md §4.2); ssh-keygen и прочий subprocess — asyncio.create_subprocess_exec; тяжёлое file I/O — hass.async_add_executor_job.
  • Запрещены: time.sleep, subprocess.run, requests, os.system, чтение/запись файлов через open() без executor.
  • Polling сенсора: SCAN_INTERVAL = timedelta(seconds=...) берётся из конфига (scan_interval, дефолт 300). Сенсор реализует async_update, не update.

GitManager — публичный контракт (см. docs/architecture.md §8)

class GitManager:
    async def initialize(self) -> None: ...
    async def push(self) -> GitResult: ...
    async def pull(self) -> GitResult: ...
    async def fetch(self) -> GitResult: ...
    async def commit(self, message: str | None = None) -> GitResult: ...
    async def get_status(self) -> SyncStatus: ...
    async def get_local_commit(self) -> CommitInfo: ...
    async def get_remote_commit(self) -> CommitInfo: ...
    async def get_changed_files(self) -> list[FileChange]: ...
    async def generate_ssh_key(self) -> str: ...
    async def test_connection(self) -> bool: ...

Read the full file on GitHub · 89 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 89 lines · 0 tokens per session scan A 15cfef29dd1e

Subscribe to this mod's changes

home-assistant is a cursor rule published in the GitHub repository ckrl/ha-gitops (4 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,627 tokens. A static security scan graded it A with 2 findings (makes network calls, runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.