Skip to content

[FEATURE] Auto-backup edited entities on every write (automations/scripts/scenes/dashboards/helpers) #1288

Description

@kingpanther13

What would you like to see?

Automatic per-edit backups for the MCP server's write tools — ha_config_set_automation, ha_config_set_script, ha_config_set_scene, ha_config_set_helper, and dashboard writes. Before each write, dump a full backup of whatever is being modified (the entire automation, the entire dashboard, the entire script, etc. — not a diff, not just the changed keys) to a timestamped file in a dedicated folder on HA (e.g. /config/.ha_mcp_backups/...).

Backup in whatever form it's stored locally — JSON for storage-mode entities, YAML for YAML-mode dashboards/packages, etc. Don't transform.

Today, only the beta YAML editing tool (ha_config_set_yaml) does this — to .ha_mcp_tools_backups/. None of the standard write tools do.

Toggle (ships with the first PR)

A single enable/disable toggle, mirrored in both places like the existing enable_tool_search setting:

  • homeassistant-addon/config.yaml + schema (and homeassistant-addon-dev/config.yaml)
  • The web settings UI

Not deferred — both surfaces ship with the PR that closes the first half of this issue.

Browse / restore interface (follow-up)

Capturing the data here so it doesn't get lost. File a separate follow-up issue once this one closes.

A user-facing UI for browsing the backup folder, viewing diffs, and one-click restore — likely inside the web settings panel from #960. Rough shape:

  • List backups grouped by entity (automation/script/scene/dashboard/helper)
  • Per-entry: timestamp, originating tool call, side-by-side diff against current state
  • "Restore" button that re-applies the captured backup through the same write tool that produced it
  • Retention/cleanup controls (max backups per entity, max age, total size cap)

Out of scope for the first PR but tracked here so the data shape, file layout, and metadata captured during writes don't paint the follow-up into a corner. The first PR should write enough metadata alongside each backup file (entity_id, domain, tool name, timestamp, maybe the agent's natural-language intent if available) to make the follow-up cheap.

Why do you need this?

From discussion #984: users want the same "agent went sideways, undo it" safety net git gives them in code repos. Today the options are:

  • ha_backup_create — heavy full HA snapshot, manual, loses entity data between snapshots
  • The agent showing diffs in chat — only useful if the user catches it in time
  • ha_config_set_yaml's built-in backup — only covers that one beta tool

For the common case (agent edits an automation/script/dashboard, gets it wrong, user notices an hour later), nothing covers it. Per-edit backups give clean side-by-side comparison, bound the blast radius, and remove the current "remember to ask the agent to back up first" pattern.

Additional context

  • Discussion YAML-level diffing & rollback #984, especially richardgaywood's clarifying reply (2026-05-15): this is about the payloads flowing through MCP write tools, not user-authored configuration.yaml.
  • Existing precedent: ha_config_set_yaml's backup=True parameter + .ha_mcp_tools_backups/ folder. The new system could reuse that path or place a sibling under /config/.
  • Toggle precedent: enable_tool_search lives in both addon config and web settings — mirror that.
  • Related: [FEATURE] Advanced settings panel in web UI + beta-features opt-in #1164 (advanced settings panel) — the eventual home for the browse/restore UI.
  • Out of scope: full snapshot rollback (ha_backup_create/ha_backup_restore already cover that).

richardgaywood offered to author the PR in the original discussion post.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions