Hi Home Assistant community!
I’m excited to share a script I’ve developed for dynamically toggling comments on blocks of code in YAML files, which I’m currently using to manage automations and other configuration changes in Home Assistant. This script offers a streamlined way to enable or disable specific blocks of code, such as configurations that you might only need under certain conditions (e.g., vacation settings, device states, group states, etc.).
Example changes in frigate.yaml
When Home | When Away |
---|---|
|
|
Features of the Script:
- Toggle Comment Blocks On/Off: Quickly comment or uncomment entire blocks of code with simple state commands (
on
,off
). - Show Block Content: Preview the content of a block without modifying it (
show
). - Backup Creation: Optional automatic creation of
.bak
files to ensure you can always revert changes if needed. - Customizable Tags: Use HTML-like tags around blocks to easily identify and manage multiple sections of your configurations.
- Error Handling: Provides helpful feedback when a block or file is missing, improving debugging and usability.
- Flexible: Can be run from the terminal, or as an Action in Developer tools and Automations.
- Simple: No need to maintain multiple versions of configuration files.
How the Community Can Help:
I’d love to get feedback from other users on how I might improve the script. Do you have ideas for additional features or improvements? I’m also curious to hear how others could integrate this into their specific setups. I use this mainly for changing frigate.yaml for my Frigate add-on based on the home and away status of my family, but it can be used on any file that uses #
for comments.
As always, be careful with your critical files until you have mastered the script on test files!
Get Started:
The script is available on GitHub, along with full documentation, including installation steps and usage examples. I’ve tried to keep the readme concise but informative, so head over to GitHub for more details!
Feel free to leave suggestions here or contribute directly on GitHub! Thanks for taking the time to check it out, and I’m looking forward to seeing how the community can help me take this script to the next level!