3.8 KiB
3.8 KiB
Home Assistant OpenCode Rules
You are working directly inside a live Home Assistant installation (/homeassistant).
Critical Mandates & Approval Rules
- Read-Only by Default: Only read files and query APIs when investigating. Never modify files or call state-changing services without explicit user confirmation.
- Explicit Confirmation: Show the exact diff or file content to be written before making any change. Wait for user approval ("yes", "go ahead").
- One Change at a Time: Apply minimal changes, report what changed, and verify before proceeding.
- No Unsolicited Work: Do not refactor, clean up, or change unrelated code/files beyond the requested scope.
- Project Context Protocol:
- Associate requests with a stable project ID in
PROJECTS.md(e.g.P013). - Read
PROJECTS.mdbefore starting work. Record durable context under the project ID. - Never mark a project
Completeunless the user explicitly confirms completion. Ask: "Should I close Pxxx?"
- Associate requests with a stable project ID in
Off-Limits & Restricted Paths
Never read, write, or access:
.storage/,.cloud/,deps/,tts/home-assistant_v2.db*,home-assistant.log*secrets.yaml(never expose or log secret contents)
Use MCP tools (get_devices, get_areas, get_entity_details, get_history) or CLI tools (hab) instead of accessing internal storage or database files.
Configuration & Architecture Gotchas
- Directory Includes in
configuration.yaml:automation: Uses!include_dir_merge_list automations/-> Active automations are inautomations/, NOT rootautomations.yaml(which is legacy/inactive).script: Uses!include_dir_merge_named scripts/-> Active scripts are inscripts/, NOT rootscripts.yaml.group: Uses!include_dir_merge_named group/-> Active groups are ingroup/, NOT rootgroups.yaml.packages: Uses!include_dir_named packages/.template: Uses!include_dir_merge_list templates/.sensor: Uses!include_dir_merge_list sensor/.
CLI & Tooling Reference
Shell YAML Queries (yq)
- Always use
yq(mikefarah/Go version) for CLI YAML processing. PyYAML and Ruby YAML crash on HA tags (!include,!secret). - Example:
yq '.homeassistant.latitude' configuration.yaml
Home Assistant Admin (hab CLI)
- Pre-authenticated CLI tool for managing HA via terminal (
hab <command> --json). - Common commands:
- Entities & Devices:
hab entity list --domain light --json,hab device list --json - Automations/Scripts:
hab automation list --json,hab script list --json - Dashboards:
hab dashboard list --json,hab dashboard get <id> --json - Operations:
hab system health --json,hab backup create
- Entities & Devices:
Zigbee Toolkit (zigporter CLI)
- Handles cascade renames across automations, scripts, scenes, and Lovelace dashboards.
- Command:
zigporter rename-entity light.old light.new --apply(Defaults to dry-run if--applyomitted). - Note:
zigporter migraterequires physical interaction and must NOT be run by AI.
Safe Configuration Writing (MCP)
- Prefer
write_config_safe(file_path, content, dry_run=true)to pre-validate before writing. - Always read the target file first and preserve all existing content when writing.
Mandatory YAML Style Rules
- Indentation: 2 spaces (no tabs).
- Strings: Double quotes (
"..."). Exceptions: entity IDs, action names, area IDs, device classes, modes. - Booleans: Lowercase
true/falseonly. Neveron/off/yes/noas YAML booleans. - Lists & Maps: Block style only. Never flow style
[1, 2]or{key: val}. - Action Targets: Always use
target:block (target: entity_id: light.room). Do not putentity_idinsidedata:or at root action level. - Templates: Use
states('sensor.x')andis_state(...)helpers. Never use direct state object access (states.sensor.x.state).