This project implements a workflow that treats your Home Assistant server as a Read-Only Runtime and your local machine as the Source of Truth. This prevents state corruption and enforces atomic deployments.
- Manifest Driven: We do not guess file paths. A
ha_manifest.yamldefines exactly where files live and how to edit them (Append vs. Create). - Atomic Deployment:
Stop Core->Push Files->Start Core. No writing to a running server. - Versioned State: Every action (Pull or Inject) is automatically committed to a local Git repo.
- Python 3
pipgit- SSH access to your Home Assistant server (public key authentication recommended)
Install Python dependencies:
pip install paramiko pyyaml-
Generate Manifest: Run
ha_setup.pyonce to scan your Home Assistant server and generate theha_manifest.yamlmapping file.python ha_setup.py --host <HA_IP> --user <SSH_USER> --key <PATH_TO_SSH_KEY>
--host: IP address of your Home Assistant server.--user: SSH username (default:root).--key: Path to your SSH private key (default:~/.ssh/id_rsa).--root: Path to the Home Assistant config directory (default:/config).
Use ha.py for daily management.
Pull the current state from the server to your local repository.
python ha.py pullInject new configurations or modify existing ones. This updates the local files and creates a git commit.
python ha.py inject <CATEGORY> <NAME> "<YAML_CONTENT>"category: One ofautomations,scripts,scenes,dashboards.name: Identifier for the item (used for filename or commit message).content: The YAML content to inject.
Example:
python ha.py inject automations night_mode "- alias: Night Mode\n trigger: ..."Deploy your local state to the server. This performs a configuration check, stops the core, pushes files (deleting remote files not present locally), and restarts the core.
python ha.py deployha_setup.py: Connects to the server via SSH/Paramiko, readsconfiguration.yaml, and detects file structures (e.g.,!includevs!include_dir_merge_list). Generatesha_manifest.yaml.ha.py: The CLI tool.- Pull: Uses
rsyncto download files based on the manifest. - Inject: Modifies local files based on strategy (Append or Create) and commits to local git.
- Deploy: Checks config via
ha core check, stops core,rsync --deleteto server, starts core.
- Pull: Uses
This workflow captures and manages the following:
- YAML Configuration:
automations.yaml,scripts.yaml,configuration.yaml, etc. - UI-Configured Integrations: By syncing the
.storagedirectory, integrations configured via the UI (like MQTT, Z-Wave JS) are preserved. - HACS:
- Code:
custom_components/andthemes/are synced. - State: HACS state (tracked repositories) in
.storage/hacs.*is synced.
- Code:
- Add-on Configuration: If you use the
/config/addon_configsfeature (HA 2023.12+), those configurations are captured. - Local Assets: The
www/directory is synced.
- Add-on Installation: The installation state of Add-ons (managed by Supervisor) is not captured. If you restore to a fresh server, you must manually re-install Add-ons (though their configs in
addon_configswill be waiting for them). - OS/Supervisor Settings: Network configuration, OS updates, and Supervisor specific settings are generally outside
/configand not captured.
- Secrets: Since this workflow syncs
.storageandsecrets.yaml, your local git repository will contain sensitive tokens and passwords. Ensure your local machine is secure. - SSH: The scripts use SSH for communication. Ensure your SSH keys are secure.
- Downtime: The
deploycommand stops the Home Assistant core, so there will be a brief downtime during deployment.