What Happens When You Let AI Edit Your Home Assistant Config?
Maybe you’ve had the same experience as me doing home automation.
- Buy gadgets! (Fun!)
- Set up gadgets at home. (Less fun…)
- Get gadgets to communicate and interoperate. (Out of patience now going outside)
If you’ve gotten this far you’ve probably at least heard of Home Assistant. Home Assistant is an incredibly powerful open source home automation management suite. It can do almost anything, but it’s also a lot to learn. If you’re like me, you’re very impatient to get this stuff to just work. AI tools like ChatGPT can be incredibly useful when figuring out how to set up Home Assistant, but what if you could get AI tools to actually set up automations and dashboards for you? Well, you can. Here’s how I’ve been doing it.
By the end of this guide, you’ll be able to use an AI coding agent to modify your Home Assistant YAML configuration and deploy changes back to your instance.
Warning!
You can totally bork your Home Assistant server this way! You should be backing things up and have a plan to restore to a previous state if you get in trouble. This guide offers some strategies for doing this, but not every edge case or failure mode has been tested. If you’re not willing to take some chances, better to just go slowly through the GUI. There’s no life guard on duty! Proceed with caution!
Prerequisites
Before following this guide, you should have a running Home Assistant instance and be able to access the Settings → Add-ons page. You’ll need a computer with a terminal (Mac or Linux works best, Windows with WSL is fine) and feel comfortable running a few copy-and-paste commands. This guide assumes your Home Assistant configuration is stored in YAML mode, or that you’re interested in exporting and managing your YAML files. You’ll also need Node.js and npm installed so you can use the helper scripts in the project repository — these are used to sync configuration files between your local machine and Home Assistant. No advanced programming background is required, but basic familiarity with files, folders, and editing text will help.
What is Home Assistant?
At a high level, Home Assistant works like a control plane for your house. It runs as a service and maintains a shared state model of everything it knows about like lights, switches, sensors, climate devices, presence, and so on. Each device is represented as an entity with a current state and a set of attributes. When something changes, an event is emitted. Automations subscribe to those events, evaluate conditions, and execute actions. Dashboards don’t control devices directly, they read and write to that same state model.
Most of this behavior is defined in configuration files, primarily written in YAML. Integrations, entities, automations, scripts, and helpers are all declared in files. Home Assistant loads that configuration at startup, merges it with what it discovers at runtime, and continuously reconciles the two. The result is a system where the logic of your home lives in versionable text files, while the runtime engine does the work of listening, reacting, and keeping everything in sync.
You can modify Home Assistant and the underlying YAML either via GUI or by editing the YAML files directly.
Selecting a coding agent
There are many options for coding agents. You can use them from the command line like Claude Code, Codex, Gemini or OpenCode. There are also agentic IDEs (integrated development environments) like Cursor, Windsurf or Copilot. They all work in a similar way in the sense that they will use a model that you select to write code for you based on your prompts and one or more instructions files and will provide some developer experience tools on top of that. For the purposes of this post we’ll use Cursor because it makes examining the YAML files easy and is fairly intuitive to work with. You should experiment with all these tools though and create a workflow that is the most fun and productive for you.
Follow the instructions on Cursor’s website to get the IDE installed. Once you have it set up, we can move on to the next step.
SSH access
SSH (secure shell) is a protocol for establishing an encrypted client-server connection between two computers using public key cryptography. Basically, you will create a key pair (one public, one private) on your machine and put the public key on the Home Assistant machine. This way you can access the Home Assistant file system remotely without having to authenticate through the UI.
Here’s the command for creating a keypair on a mac. ed25519 is the encryption algorithm and the -C flag provides a comment to identify the key. You can replace [email protected] with your own designation
ssh-keygen -t ed25519 -C "[email protected]"
Here’s a more detailed post about generating and using SSH key pairs.
I typically do not select a pass phrase for this kind of SSH use case. A passphrase would add a second factor to the authentication and be more secure for connections that might be exposed to the public internet. In this case, your SSH connection is going to be between a local development machine and a home assistant server on your internal network. Not selecting a passphrase reduces friction, but also lowers security.
Once you’ve created a public and private key pair, You need to add the public key to the home system. You’ll need to go to your Home Assistant UI and tnstall the SSH & Web Terminal add on and configure it.
Go to Settings → Add-ons → Add-on Store install SSH & Web Terminal (official) and start it then enable Start on boot
Once the add-on is set up, you’ll add the public key you’ve created to the list of authorized keys in the configuration tab. Go back to your terminal and use the following command to write your new public key to your clipboard
cat ~/.ssh/id_ed25519.pub | pbcopy
Then in the Terminal & SSH configuration tab, paste the key in the Authorized Keys, save and restart HA.
Now that you’ve set up your key and restarted HA, let’s check if you have SSH access.
ssh [email protected] -p 2222
You should see something like this:
If not you’ll have to debug your ssh configuration.
Editing Files
This is the manual version in case you want to mess around with this yourself. If you just want to use the scripts I created skip to the next section. Most coding agents are designed to operated in the context of a repository. Basically a directory. You’re going to want to SCP (secure copy) the config files you want to work on into a local folder. SCP is a tool that operates similarly to SSH, but copies files instead of providing a command prompt. To copy the entire HA config folder to local you’d do something like
mkdir homeassistant-config && cd homeassistant-configscp -P 2222 [email protected]:/config/{configuration.yaml,automations.yaml,scripts.yaml,scenes.yaml,templates.yaml,secrets.yaml} .
This will create a homeassistant-config directory and download
You’ll also need to get the available entities, which are all the connected devices you have set up in HA already. Your agent will need to know about these in order to set them up in automations, scenes, dashboards, etc.
You can do something like
scp -P 2222 [email protected]:/config/.storage/core.entity_registry .
Once you have these files, you have your agent of choice modify them and then you can SCP them back up to HA. Easy! Just kidding! This is a total slog an exactly the kind of fussy complexity you can here to get away from!
I did some of this for you
I fussed with a lot of this stuff so you don’t have to. I created a github repo called ha-configs. This repo offers a few thingsAutomatic SSH scripts. You can call a few basic npm scripts and you don’t have to worry about the background scp processes and config. just set up your .env file and the scripts in the repo handle the rest.Version control. There are 2 main things you want to think about. One is that your home assistant configs can contain sensitive values, like certificates and API keys. This repo is designed to ignore those files and not commit them to any repository where they can be exposed. Two, you may screw up your configs by vibe coding them all to pieces. ha-configs maintains snapshots of your config history and lets you roll back to a previous revision if you mess up.Agent instructions. This repo contains an AGENTS.md file (and symbolic links to the custom rules files for most agents) that will provide basic instructions to your agent, so you can just focus on features. These instructions have worked well for me, but ymmv and you can edit as you desire.
ok, so let’s try setting this repo up and getting started.
Clone the repo and install dependencies
git clone [email protected]:ohall/ha-configs.gitcd ha-configsnpm i
Create your own .env file
cp .env.example .env# Edit .env with your Home Assistant SSH credentials
Edit your .env file, here’s an example:
# SSH Connection (required)HA_SSH_HOST=homeassistant.localHA_SSH_PORT=2222HA_SSH_USERNAME=rootHA_SSH_PASSWORD=your-password# Or use SSH key authentication (recommended)# HA_SSH_PRIVATE_KEY_PATH=/path/to/private/key# Paths (required)HA_REMOTE_CONFIG_PATH=/configHA_LOCAL_BACKUP_PATH=./backupsHA_LOCAL_CURRENT_PATH=./current# File patterns (optional)HA_INCLUDE_PATTERNS=*.yaml,*.yml,automations/*,scripts/*HA_EXCLUDE_PATTERNS=*.log,*.db,*.db-shm,*.db-wal
Ok, now let’s see if this thing is on. Try the following command:
npm run sync
If you’re set up correctly, you should see something like this, which indicates you’ve pulled the config files from HA and created a backup.
Let the vibes in
Now that you have the scripts set up it’s time to turn and agent loose on them. I like to user Cursor, because it has nice tools and UX and I can easily examine and manually edit files. YMMV.
Let’s first look at the context this agent is operating with. The repo you cloned has an AGENTS.md file. It contains the basic instructions the agent will get for each context window.
Home Assistant Configuration Agent InstructionsRoleYou are a specialized agent responsible only for modifying Home Assistant configuration files to implement, fix, or improve home automations.Scope of WorkYou may modify: • configuration.yaml • automations.yaml • scripts.yaml • scenes.yaml • helpers (input_* entities) • packages/* • blueprints/* • YAML files used directly by Home Assistant integrationsYou must NOT modify: • Any scripts, tooling, or workflows used for config syncing, backups, or deployment • Git hooks, CI/CD configs, or file-sync mechanisms • Non-Home-Assistant services unless explicitly instructedPrimary Objectives • Solve the stated home automation problem correctly and minimally • Prefer simple, declarative YAML over complex logic • Reuse existing entities, helpers, and automations when possible • Follow Home Assistant best practices and current schema conventionsModification Rules • Make the smallest change necessary to achieve the goal • Do not refactor unrelated automations • Do not rename entities unless explicitly requested • Preserve existing comments and formatting where practical • Avoid breaking changes unless explicitly requiredAutomation Design Principles • Prefer trigger → condition → action clarity • Use choose sparingly and only when justified • Use helpers (input_boolean, input_number, etc.) instead of hard-coded state where appropriate • Avoid polling when event-based triggers are available • Ensure automations are idempotent and safe to re-runValidation & SafetyBefore finalizing changes: • Ensure YAML is syntactically valid • Ensure entity IDs are valid and consistent • Avoid race conditions and infinite loops • Assume automations may run concurrentlyOutput Expectations • Return only the modified or newly added Home Assistant config sections • Clearly indicate which file(s) each change belongs to • Do not include explanations unless explicitly requested • Do not include deployment or restart instructions unless askedAssumptions • All available entities can be found in the entities.txt file. • Home Assistant is running in YAML mode (not UI-only) • Existing configurations are authoritative • The goal is correctness, maintainability, and long-term stability
Based on this context, your prompts can really just include the specific features you want to implement and not directions on how to implement them since those will be present already. You should modify this instructions file to suit your needs.
Let’s create a dashboard as an example. Here’s my prompt to start
Create a new lovelace dashboard that includes: - a button to turn on and off the lights in the living room- button to send my robot vacuum hond- a button to unlock the doors of my Subaru.
When I entered this prompt in Cursor, it created a new dashboard called “Quick Controls” in the ui-lovelace.yml file where dashboards are configured.
ok, let’s see what it looks like in HA. Use this command to push it to your HA instance
npm run push
Now perform a “Quick Relaod” under Developer Tools
If you already have a dashboard, you’ll probably see a new tab. If you don’t yet have one, the agent will probably created one for you. AI programming is by definition non-determinative, so your results will definitely vary based on the model you’re using and the configurations of the agent. Mine looks like this:
Now you got to test it out. Sometimes these configurations will work, sometimes they won’t. Sometimes the agent will screw up. Sometimes it’ll get it right on the first try. But your ability to iterate will be sped up. Any time you come up with an idea to automate your smart devices, you can pop it into a prompt and see what happens.
Have fun and let me know how it works in the comments!