Explains the critical v2 fix for handling templates in included files: - Why v1 didn't work (only scanned configuration.yaml) - What v2 fixes (scans all .yaml files, handles list format) - Updated example showing binary_sensors.yaml format - Clearer installation and troubleshooting instructions
Home Assistant Legacy Template Migration
✨ v2 UPDATE: Fixed script now properly handles templates in included files (sensors.yaml, binary_sensors.yaml)!
Automatically migrates legacy platform: template syntax to modern template: syntax in Home Assistant.
What's New in v2
The original script looked only at configuration.yaml, but many Home Assistant configurations use !include directives to split sensors into separate files like:
binary_sensors.yamlsensors.yamlpackages/*.yaml
v2 fixes:
- ✅ Scans ALL .yaml files in
/config/and/config/packages/ - ✅ Handles
- platform: template(list item format with dash) - ✅ Properly extracts sensors from
sensors:blocks - ✅ Handles multiline templates with
>operator - ✅ Correct indentation for modern
template:format - ✅ Counts sensors correctly from included files
Why Migrate?
Home Assistant is deprecating the legacy platform: template syntax in favor of modern template: syntax. Starting in version 2026.6, the old syntax will stop working.
This script safely migrates all your legacy template definitions:
- Binary sensors (
binary_sensor: !include binary_sensors.yaml) - Sensors (
sensor: !include sensors.yaml) - Packages (if you use
/config/packages/)
Features
✅ Safe Migration: Creates timestamped backups before making changes
✅ Automatic Conversion: Converts all legacy fields to modern syntax
✅ Field Mapping:
friendly_name→namevalue_template→stateicon_template→iconentity_picture_template→pictureavailability_template→availabilityattribute_templates→attributes
✅ Rollback Support: Includes restore script in backup directory
✅ Clean Removal: Removes legacy definitions from original files
✅ Modern Addition: Adds new template: section to configuration.yaml
Installation
SSH Add-on or Terminal
cd /config
wget https://gitea.hideawaygaming.com.au/jessikitty/ha-template-migration/raw/branch/main/migrate_templates.sh
chmod +x migrate_templates.sh
bash migrate_templates.sh
What It Does
- Scans all YAML files in
/config/and/config/packages/ - Extracts legacy template definitions
- Converts to modern syntax
- Backs up original files to
/config/backups/template_migration_TIMESTAMP/ - Removes legacy
- platform: templateblocks - Adds modern
template:section to configuration.yaml
Example Migration
Before (binary_sensors.yaml)
- platform: template
sensors:
router_authenticated:
friendly_name: "Router Authenticated"
value_template: >
{{ states('input_text.router_token') not in ['unknown', '', 'unavailable', ''] }}
icon_template: >
{% if states('input_text.router_token') not in ['unknown', '', 'unavailable', ''] %}
mdi:check-circle
{% else %}
mdi:close-circle
{% endif %}
After (configuration.yaml)
template:
- binary_sensor:
- unique_id: router_authenticated
name: "Router Authenticated"
state: >
{{ states('input_text.router_token') not in ['unknown', '', 'unavailable', ''] }}
icon: >
{% if states('input_text.router_token') not in ['unknown', '', 'unavailable', ''] %}
mdi:check-circle
{% else %}
mdi:close-circle
{% endif %}
After Running
- Review the new
template:section at end of configuration.yaml - Check config:
ha core check - Restart HA:
ha core restart - Verify all template entities still work
If Something Goes Wrong
# Restore from backup
cd /config/backups/template_migration_TIMESTAMP
bash restore.sh
ha core restart
Requirements
- Home Assistant OS or Supervised (with SSH add-on)
- Core or Docker installations (adjust paths as needed)
- Bash shell
What Gets Migrated
✅ Template binary sensors
✅ Template sensors
✅ All template fields (value, icon, availability, attributes, etc.)
✅ Multiline templates with > operator
✅ Templates in !include files
Technical Details
- Uses pure bash + awk (no Python dependencies)
- Handles complex YAML indentation
- Preserves template logic exactly
- Safe for large configurations (handles 67+ sensors)
Version History
- v2 (2025-12-23): Fixed to handle
!includefiles and list-item format - v1 (2025-12-23): Initial release (only scanned configuration.yaml)
License
MIT License - feel free to use and modify!
Support
Issues? Check the Gitea repository or file a bug report.