My Smart Home Just Got a New Brain: Using Claude Code to Tidy Up Home Assistant

I’ve always loved the flexibility of Home Assistant, but let’s be honest: maintaining a complex setup as it grows can feel like a second job. Between the custom YAML configurations, legacy devices, and the constant evolution of the HA dashboard, things get messy.

Recently, I decided to see if Claude Code—Anthropic’s agentic CLI tool—could handle the “spring cleaning” for me. After a weekend of testing, I can say it’s a game-changer for terminal-focused automation.


⚠️ First Rule of AI Automation: Backup Everything

Before we talk about the cool stuff, a word of caution: Because we are using sshfs, Claude Code is writing directly to your live files. One small “hallucination” in a YAML indentation can take your whole system down.

Do not start this without a fresh snapshot. Go to Settings > System > Backups and create a full backup. Better yet, if you’re on a Pi or Mini PC, clone the SD card or drive.


The Setup: Bridging the Gap

My Home Assistant instance runs on a dedicated mini PC, but I wanted to use Claude Code from my main workstation.

1. Mounting the Config via SSHFS

I used sshfs to make my remote /config folder appear as a local directory on my Zorin machine. Note that I’m using a local IP here; you’ll want to use your own internal address.

Bash

# Mounting the remote mini PC config to a local folder
mkdir ~/ha-config
sshfs root@192.168.xxx.xxx:/config ~/ha-config

Tip: If you’re using the “Advanced SSH & Web Terminal” add-on in HA, make sure SFTP is enabled in the add-on’s configuration!

2. Launching the Assistant

Bash

cd ~/ha-config
claude

Step 1: The Security Audit (The “Secrets” Move)

While Claude was scanning my files, it noticed something I’d overlooked: I had several API keys and authorization tokens hardcoded directly into my configuration.yaml and some custom integrations.

The Logic:

Claude didn’t just point this out; it explained that this was a security risk (especially if I ever back up my config to GitHub). It suggested moving them to secrets.yaml.

The Execution:

I gave it the go-ahead, and it was impressive to watch. It:

  1. Created/Updated my secrets.yaml file with the new keys.
  2. Replaced the hardcoded strings in configuration.yaml with !secret pointers.
  3. Verified the syntax was still valid for Home Assistant.

Step 2: Dashboard Refresh

My “What is on” dashboard tab was a mess—it was missing several newer devices I’d added.

The Prompt:

“Look at ui-lovelace.yaml. In the ‘What is on’ tab, find the current ‘Entities’ card. Compare with entities in the system and see if I am missing any. Then add the missing ones using conditional cards to show them only when they are on.

Because Claude Code uses “Solution Math”—calculating the logical outcome rather than just matching text—it understood the YAML structure perfectly. It didn’t just dump the entities at the bottom; it integrated them, respected the indentation, and even suggested a better icon for my solar production sensor.


Final Thoughts

We’ve all used AI to “write a script,” but Claude Code feels different because of its Agency. It isn’t just a chatbot; it’s an assistant that has access to your actual files. It can run a ha core check command to verify its own changes before you ever hit “Save.”

For a power user, it feels like having a senior developer sitting next to you who knows the Home Assistant documentation by heart. Just remember: Backup first, automate second.

Have you tried using agentic AI for your home automation yet? I’d love to hear about the prompts you’re using to keep your house running smoothly.

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × 5 =