A comprehensive system for managing Home Assistant configurations with automated validation, testing, and deployment - all enhanced by Claude Code for natural language automation creation.
- π€ AI-Powered Automation Creation: Use Claude Code to write automations in plain English
- π‘οΈ Multi-Layer Validation: Comprehensive validation prevents broken configurations
- π Safe Deployments: Pre-push validation blocks invalid configs from reaching HA
- π Entity Discovery: Advanced tools to explore and search available entities
- β‘ Automated Hooks: Validation runs automatically on file changes
- π Entity Registry Integration: Real-time validation against your actual HA setup
New to command line tools? No problem! We've made it super easy to get started.
Download the project and run the setup script for your operating system:
- Download or clone this repository (quick tutorial)
- Open Terminal and navigate to the project folder (how to use Terminal on Mac)
- Run the setup script:
./setup-mac.sh- Download or clone this repository (quick tutorial)
- Open Command Prompt and navigate to the project folder (how to use terminal on Win)
- Run the setup script:
setup-windows.bat- β Check that you have all required software (Python, Git, etc.)
- β Download and install Claude Code automatically if missing
- β Install any missing dependencies automatically
- β Set up the Python environment with all needed packages
- β Guide you through the next steps
- Configure your Home Assistant connection (the script will show you how)
- Open Claude Code (download here if not installed) and navigate to your project folder
- Pull your configuration by typing
make pullin Claude Code - Start creating automations with Claude Code!
That's it! The scripts handle all the technical setup for you. Claude Code makes running commands super easy - just type them directly!
This repository provides a complete framework for managing Home Assistant configurations with Claude Code. Here's how it works:
- Template Configs: The
config/folder contains sanitized example configurations (no secrets) - Validation Tools: The
tools/folder has all validation scripts - Management Commands: The
Makefilecontains pull/push commands - Development Setup:
pyproject.tomland other dev files for tooling
git clone [email protected]:philippb/claude-homeassistant.git
cd claude-homeassistant
make setup # Creates Python venv and installs dependenciesCopy the example environment file and configure your settings:
cp .env.example .env
# Edit .env with your actual Home Assistant detailsThe .env file should contain:
# Home Assistant Configuration
HA_TOKEN=your_home_assistant_token
HA_URL=http://your_homeassistant_host:8123
# SSH Configuration for rsync operations
HA_HOST=your_homeassistant_host
HA_REMOTE_PATH=/config/
# Local Configuration (optional - defaults provided)
LOCAL_CONFIG_PATH=config/
BACKUP_DIR=backups
VENV_PATH=venv
TOOLS_PATH=toolsRequired: Install the Advanced SSH & Web Terminal add-on for Home Assistant, which provides SSH/SFTP access needed for the rsync operations in this project.
Click to expand SSH setup instructions
# Generate a new SSH key pair for Home Assistant
ssh-keygen -t ed25519 -f ~/.ssh/homeassistant -C "[email protected]"
# Verify the key files were created
ls -l ~/.ssh/homeassistant*This creates:
~/.ssh/homeassistant(private key - keep this secure)~/.ssh/homeassistant.pub(public key - this goes into HA)
- Install the Advanced SSH & Web Terminal add-on in Home Assistant
- Configure the add-on with this YAML configuration:
username: root
password: ""
authorized_keys:
- >-
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... [email protected]
sftp: true
compatibility_mode: false
allow_agent_forwarding: false
allow_remote_port_forwarding: false
allow_tcp_forwarding: falseImportant: Replace the ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... line with the contents of your ~/.ssh/homeassistant.pub file.
- Start the add-on and ensure it's running
Create or edit your SSH config file (~/.ssh/config):
# Home Assistant SSH Configuration
Host homeassistant
HostName homeassistant.local # or your HA IP address
User root
IdentityFile ~/.ssh/homeassistant
StrictHostKeyChecking no
Note: Replace homeassistant.local with your Home Assistant's IP address if hostname resolution doesn't work.
# Test the SSH connection
ssh homeassistant
# You should see:
# Welcome to the Home Assistant command line.If successful, you can exit with exit or Ctrl+D.
To get your HA_TOKEN:
- Go to Home Assistant β Settings β People β Your Profile
- Scroll to "Long-lived access tokens"
- Click "Create Token"
- Give it a name like "Claude Home Assistant"
- Copy the token and paste it as
HA_TOKENvalue in your.envfile
make pull # Downloads YOUR actual HA config, overwriting template filesImportant: This step replaces the template config/ folder with your real Home Assistant configuration files.
- Edit your real configs locally with full validation
- Use Claude Code to create automations in natural language
- Validation hooks automatically check syntax and entity references
make push # Uploads changes back to your HA instance (with validation)- Template Start: You begin with example configs showing proper structure
- Real Data: First
make pulloverwrites templates with your actual HA setup - Local Development: Edit real configs locally with validation safety
- Safe Deployment:
make pushvalidates before uploading to prevent broken configs
This gives you a complete development environment while only modifying your HA instance when completed.
This project uses make commands for configuration management. If you don't have make installed:
macOS:
xcode-select --install # Installs Command Line Tools including makeWindows:
- Option 1: Use WSL (Windows Subsystem for Linux) - recommended
- Option 2: Install via Chocolatey:
choco install make - Option 3: Use Git Bash (includes make)
- Option 4: Install MinGW-w64
Alternative: If you can't install make, you can run the underlying commands directly by checking the Makefile for the actual command syntax.
βββ config/ # Home Assistant configuration files, downloaded from HA via script
β βββ configuration.yaml
β βββ automations.yaml
β βββ scripts.yaml
β βββ .storage/ # Entity registry (pulled from HA)
βββ tools/ # Validation scripts for Claude
β βββ run_tests.py # Main test suite runner
β βββ yaml_validator.py # YAML syntax validation
β βββ reference_validator.py # Entity reference validation
β βββ ha_official_validator.py # Official HA validation
β βββ entity_explorer.py # Entity discovery tool
βββ .claude-code/ # Claude Code project settings
β βββ hooks/ # Automated validation hooks
β βββ settings.json # Project configuration
βββ .env.example # Environment configuration template
βββ venv/ # Python virtual environment
βββ Makefile # Management commands
βββ CLAUDE.md # Claude Code instructions
make pull # Pull latest config from Home Assistant
make push # Push local config to HA (with validation)
make backup # Create timestamped backup
make validate # Run all validation testsmake entities # Show entity summary
make entities ARGS='--domain climate' # Climate entities only
make entities ARGS='--search motion' # Search for motion sensors
make entities ARGS='--area kitchen' # Kitchen entities only
make entities ARGS='--full' # Complete detailed output. venv/bin/activate
python tools/yaml_validator.py # YAML syntax only
python tools/reference_validator.py # Entity references only
python tools/ha_official_validator.py # Official HA validationThe system provides three layers of validation:
- Validates YAML syntax with HA-specific tags (
!include,!secret,!input) - Checks file encoding (UTF-8 required)
- Validates basic HA file structures
- Verifies all entity references exist in your HA instance
- Checks device and area references
- Warns about disabled entities
- Extracts entities from Jinja2 templates
- Uses Home Assistant's own validation tools
- Most comprehensive check available
- Catches integration-specific issues
Two hooks ensure configuration safety:
- Post-Edit Hook: Runs validation after editing YAML files
- Pre-Push Hook: Validates before syncing to HA (blocks if invalid)
This system supports standardized entity naming:
Format: location_room_device_sensor
Examples:
binary_sensor.home_basement_motion_battery
media_player.office_kitchen_sonos
climate.home_living_room_heatpump
With Claude Code, you can:
-
Describe automations in English:
"Turn off all lights at midnight on weekdays" -
Claude writes the YAML:
- id: weekday_midnight_lights_off alias: "Weekday Midnight Lights Off" trigger: - platform: time at: "00:00:00" condition: - condition: time weekday: [mon, tue, wed, thu, fri] action: - service: light.turn_off target: entity_id: all
-
Automatic validation ensures correctness
-
Deploy safely with
make push
The entity explorer helps you understand what's available:
# Find all motion sensors
. venv/bin/activate && python tools/entity_explorer.py --search motion
# Show all climate controls
. venv/bin/activate && python tools/entity_explorer.py --domain climate
# Kitchen devices only
. venv/bin/activate && python tools/entity_explorer.py --area kitchen- Secrets Management:
secrets.yamlis excluded from validation - SSH Authentication: Uses SSH keys for secure HA access
- No Credentials Stored: Repository contains no sensitive data
- Pre-Push Validation: Prevents broken configs from reaching HA
- Backup System: Automatic timestamped backups before changes
- Check YAML syntax first:
. venv/bin/activate && python tools/yaml_validator.py - Verify entity references:
. venv/bin/activate && python tools/reference_validator.py - Check HA logs if official validation fails
Click to expand SSH troubleshooting
-
Connection refused or timeout:
# Test if the SSH add-on is running ssh homeassistant # If this fails, check if the Advanced SSH & Web Terminal add-on is started in HA
-
Permission denied (publickey):
# Check SSH key permissions chmod 600 ~/.ssh/homeassistant chmod 644 ~/.ssh/homeassistant.pub # Verify your public key is correctly added to the HA SSH add-on config cat ~/.ssh/homeassistant.pub
-
Host key verification failed:
# Remove old host key and try again ssh-keygen -R homeassistant.local # Or if using IP address: ssh-keygen -R 192.168.1.100
-
SSH config issues:
# Test connection with verbose output ssh -v homeassistant # Check your SSH config cat ~/.ssh/config
-
Advanced SSH & Web Terminal not responding:
- Restart the add-on in Home Assistant
- Check Home Assistant logs for SSH add-on errors
- Verify the add-on configuration YAML is valid
Run these commands to verify everything is configured correctly:
# 1. Check SSH key files exist and have correct permissions
ls -la ~/.ssh/homeassistant*
# 2. Check SSH config
grep -A 5 "Host homeassistant" ~/.ssh/config
# 3. Test SSH connection
ssh homeassistant "ls /config"
# 4. Test rsync (what make pull/push uses)
rsync -avz --dry-run homeassistant:/config/ ./test/. venv/bin/activate
pip install homeassistant voluptuous pyyaml jsonschema requestsConfigure via .env file in project root (copy from .env.example):
cp .env.example .envAvailable variables:
# Home Assistant Configuration
HA_TOKEN=your_home_assistant_token # HA API token
HA_URL=http://your_homeassistant_host:8123 # HA instance URL
# SSH Configuration for rsync operations
HA_HOST=your_homeassistant_host # SSH hostname for HA
HA_REMOTE_PATH=/config/ # Remote config path
# Local Configuration (optional - defaults provided)
LOCAL_CONFIG_PATH=config/ # Local config directory
BACKUP_DIR=backups # Backup directory
VENV_PATH=venv # Python virtual environment path
TOOLS_PATH=tools # Tools directoryLocated in .claude-code/settings.json:
{
"hooks": {
"enabled": true,
"posttooluse": [".claude-code/hooks/posttooluse-ha-validation.sh"],
"pretooluse": [".claude-code/hooks/pretooluse-ha-push-validation.sh"]
},
"validation": {
"enabled": true,
"auto_run": true,
"block_invalid_push": true
}
}- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all validations pass
- Submit a pull request
Apache 2.0
- Home Assistant for the amazing platform
- Claude Code for AI-powered development
- The HA community for validation best practices
Ready to revolutionize your Home Assistant automation workflow? Start by describing what you want in plain English and let Claude Code handle the rest! π