Validate Home Assistant Config Before Restarting
In this article
Editing your Home Assistant configuration is a common task, but a single mistake can prevent the entire system from starting. This guide will show you how to validate your configuration and catch errors before you restart, saving you from downtime and troubleshooting headaches. You'll learn the built-in tools and a few best practices to keep your setup running smoothly.
What You'll Need
- Access to your Home Assistant instance (web interface or SSH).
- Basic familiarity with your configuration files (configuration.yaml and any included files).
- Optional: A code editor with YAML syntax highlighting for easier editing.
Step-by-Step
- Make a backup before making changes. Always create a backup of your configuration files before editing. This way, if something goes wrong, you can easily revert. You can use the Home Assistant Backup feature (Settings → System → Backups) or manually copy your configuration directory.
- Edit your configuration files. Make the changes you need in your
configuration.yamlor any included YAML files. Be careful with indentation—YAML is strict about spaces. Use a text editor that supports YAML to catch syntax errors early. - Use the built-in configuration check. Home Assistant has a built-in validation tool. Go to Developer Tools → YAML in the web interface. Here you'll see a section called "Check Configuration." Click the "Check Configuration" button. This will run a validation pass on your entire configuration.
- Review the output. The check will show either "Configuration valid!" or a list of errors. If there are errors, fix them and run the check again. Common errors include YAML syntax issues, invalid entity IDs, or missing required options.
- Check individual integrations. If the configuration check passes but you're still unsure about a specific integration, you can use the
homeassistant.check_configscript from the command line. SSH into your Home Assistant instance and run:python -m homeassistant --script check_config. This provides more detailed output, including warnings and deprecation notices. - Use the "Check Configuration" in the CLI (if you have it). For advanced users, you can also run the check from the command line with
ha config check(if using Home Assistant OS) or the script mentioned above. This is especially useful if you're making changes via SSH. - Restart Home Assistant. Once the configuration check passes without errors, you can safely restart. Go to Settings → System → Restart or use the
ha core restartcommand in the terminal. - Monitor the logs after restart. After restarting, check the logs (Settings → System → Logs) for any new errors or warnings that might not have appeared during the check. This helps catch issues that only occur at runtime.
Common Mistakes
- Incorrect YAML indentation: YAML uses spaces (not tabs) for indentation. A missing space or an extra space can cause a parse error. Always use consistent indentation (usually 2 spaces per level).
- Using tabs instead of spaces: Tabs are not allowed in YAML. They will cause a validation error. Configure your editor to insert spaces when you press Tab.
- Editing while Home Assistant is running: While it's possible to edit files while the system is running, it's safer to make changes during a maintenance window. If you're editing via the file editor add-on, ensure you save the file before checking.
- Forgetting to include files: If you use
!includeto split your configuration, make sure the included files exist and are correctly formatted. A missing file will cause an error. - Invalid entity IDs: When referencing entities in configuration, ensure the IDs are correct and exist. A typo in an entity ID will cause an error.
Tips
- Use a YAML linter in your editor: Many code editors have YAML extensions that highlight syntax errors in real-time. This can prevent errors before you even run the check.
- Check your configuration regularly: Even if you haven't made changes, run the configuration check periodically to catch issues from updates or automatic changes.
- Keep your configuration organized: Use separate files for different integrations (e.g.,
automations.yaml,scripts.yaml). This makes it easier to debug and reduces the chance of errors. - Use version control: If you're comfortable with Git, store your configuration in a Git repository. This allows you to track changes and revert to a known-good state easily.
- Test in a separate instance: For major changes, consider testing in a separate Home Assistant instance (like a test VM) before applying to your production system.
Troubleshooting
If the configuration check fails, here's what to do:
- Read the error message carefully: The error message usually points to the exact file and line number. Open that file and look at the line mentioned. Common issues are missing colons, incorrect indentation, or extra commas.
- Check the line above and below: Sometimes the error is not on the reported line but just before it. Look for an unclosed bracket or a missing dash.
- Use the Home Assistant forums or Discord: If you can't figure out the error, search the forums or ask for help. Provide the exact error message and the relevant part of your configuration.
- Revert to a backup: If you have a backup from before your changes, restore it and start again. This is the fastest way to get back to a working state.
- If Home Assistant is already broken: If you've already restarted and the system won't start, you can use the terminal (via SSH or the console) to edit the configuration file directly. You can also use the "Safe Mode" option from the login screen, which starts Home Assistant with minimal configuration, allowing you to fix the issue.
Frequently Asked Questions
What does "Configuration valid!" mean?
It means that Home Assistant successfully parsed your YAML files and that all required options for each integration are present. It doesn't guarantee that every integration will work correctly, but it's a strong signal that the configuration is syntactically and semantically correct.
Why does my configuration check pass but the restart still fails?
This can happen if the error is not caught by the configuration check. For example, an integration might fail to connect to a service or a device might not respond. Check the logs after restart for more details.
How often should I run the configuration check?
It's a good practice to run it after any change to your configuration files, even minor ones. It only takes a few seconds and can save you from a lot of trouble.
Can I validate my configuration without restarting?
Yes, the configuration check does not restart Home Assistant. It only validates the configuration files. You can run it as many times as you like without affecting your running system.
What is the difference between the web-based check and the CLI script?
The web-based check is quick and easy, but the CLI script (check_config) provides more detailed output, including warnings and deprecation notices. The CLI script is also useful for scripting and automation.
My configuration check shows a warning, is that a problem?
Warnings are not errors, but they indicate potential issues. For example, a deprecated option might stop working in a future version. It's best to address warnings to future-proof your configuration.