Write a config file
ha_write_config_fileWrite a file in Home Assistant's config directory, replacing its contents, with automatic validation and rollback if the configuration check fails.
Instructions
Write a file under Home Assistant's config directory. Defaults to UTF-8 text; pass encoding='base64' to write a binary file (an icon, a data file a custom integration ships) — content is then the base64 of the bytes, not the bytes themselves.
This edit is checked and reversible. After the write, Home Assistant's own configuration check runs, and if it fails the previous contents are put straight back — a bad edit cannot leave Home Assistant unable to start. The result says whether it was verified and whether it was rolled back. Editing configuration.yaml this way is the normal, supported route for a home the user has authorised; it is how a hosted install is configured at all, since there is no SSH into one. (check_config only ever validates YAML, so it says nothing about a binary write; verify defaults to off for encoding='base64' for that reason.)
It replaces the entire file — read it first with ha_read_config_file and send back the full content with your change applied, or you will delete everything else in it.
Pass verify=false when writing several files that are only valid together, then call ha_check_config yourself at the end.
A successful write does not apply the change: restart Home Assistant, or reload the relevant domain, for it to take effect.
Requires the ha:files scope. Prefer a purpose-built tool where one exists: helpers via ha_set_helper and automations via ha_set_automation both apply immediately and cannot break startup.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File relative to the config root, e.g. 'configuration.yaml'. | |
| verify | No | Check the configuration afterwards and restore the file if it fails. Default true for utf8, false for base64 (check_config can't validate binary content). | |
| content | Yes | The complete new contents of the file (base64 if encoding='base64'). | |
| encoding | No | 'utf8' (default) for text; 'base64' for binary content. | |
| instance_id | Yes | The instance this write is meant for (as listed by vomehome_list_instances). Required, and checked against the one this session is actually targeting: if they differ the write is refused rather than applied to the wrong home. |