-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Add template migration examples #42149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cef2139
Add template migration examples
Petro31 52a0e07
Apply sentence-style capitalization
c0ffeeca7 b88add8
Apply suggestions from code review
c0ffeeca7 e0a3213
address comments
Petro31 5c94af4
remove notes that mess up formatting and keep the items as part of th…
Petro31 3ce1186
update restart bullet
Petro31 9ae7d4e
fix lint text
Petro31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2792,3 +2792,359 @@ The blueprint can now be used for creating template entities. | |||||||
| Event `event_template_reloaded` is fired when Template entities have been reloaded and entities thus might have changed. | ||||||||
|
|
||||||||
| This event has no additional data. | ||||||||
|
|
||||||||
| ## Legacy template deprecation migration guide | ||||||||
|
|
||||||||
| Legacy template entities are deprecated and will be removed in Home Assistant 2026.6.0. The deprecated template entities will produce a repair that guides you through the migration. | ||||||||
|
|
||||||||
| ### Migrating a legacy sensor into a new template section | ||||||||
|
|
||||||||
| This example covers how to migrate a legacy template sensor into modern syntax. | ||||||||
|
|
||||||||
| Take the example `configuration.yaml` file | ||||||||
|
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: | ||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
|
|
||||||||
| # Legacy template configuration | ||||||||
| - platform: template | ||||||||
| sensors: | ||||||||
| my_light_count: | ||||||||
| friendly_name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}" | ||||||||
| ``` | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
| To get started with the migration: | ||||||||
|
|
||||||||
| 1. Remove the `sensor` template definition from the `configuration.yaml` `sensor:` section. | ||||||||
|
|
||||||||
| Delete the following YAML from `configuration.yaml` file. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # Legacy template configuration | ||||||||
| - platform: template | ||||||||
| sensors: | ||||||||
| my_light_count: | ||||||||
| friendly_name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}" | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| Make sure to keep all the other platforms in the sensor section. Your `configuration.yaml` file would look like this after the change: | ||||||||
|
|
||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
| ``` | ||||||||
|
|
||||||||
| 1. Add the modern syntax provided by the repair. | ||||||||
|
|
||||||||
| The repair would provide the following YAML. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| template: | ||||||||
| - sensor: | ||||||||
| - default_entity_id: sensor.my_light_count | ||||||||
| name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| state: '{{ states.light | selectattr(''state'', ''eq'', ''on'') | list | count }}' | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| This YAML should be added to the `template:` section inside `configuration.yaml`. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: | ||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
|
|
||||||||
| # Copied example | ||||||||
| template: | ||||||||
| - sensor: | ||||||||
| - default_entity_id: sensor.my_light_count | ||||||||
| name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| state: '{{ states.light | selectattr(''state'', ''eq'', ''on'') | list | count }}' | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| If you are migrating multiple template entities, ensure there is only 1 `template:` section. Do not keep duplicate `template:` sections. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: | ||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
|
|
||||||||
| template: | ||||||||
|
|
||||||||
| # Migrated sensor | ||||||||
| - sensor: | ||||||||
| - default_entity_id: sensor.my_light_count | ||||||||
| name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| state: '{{ states.light | selectattr(''state'', ''eq'', ''on'') | list | count }}' | ||||||||
|
|
||||||||
| # Migrated cover | ||||||||
| - cover: | ||||||||
| - default_entity_id: cover.garage | ||||||||
| name: Garage Cover | ||||||||
| state: '{{ is_state(''binary_sensor.relay'', ''on'') }}' | ||||||||
|
|
||||||||
| # Migrated light | ||||||||
| - light: | ||||||||
| - default_entity_id: light.skylight | ||||||||
| name: Skylight | ||||||||
| state: '{{ is_state(''binary_sensor.crank'', ''on'') }}' | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| 1. Restart Home Assistant by going to **Settings** three dotted menu and selecting **Restart Home Assistant**. Or reload template entities by going to **Developer tools** **YAML** tab and selecting the **Template entities** reload button. | ||||||||
|
|
||||||||
| ### Migrating a legacy sensor into an existing template section | ||||||||
|
|
||||||||
| This example covers how to migrate a legacy template sensor into modern syntax. | ||||||||
|
|
||||||||
| Take the example `configuration.yaml` file | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: | ||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
|
|
||||||||
| # Legacy template configuration | ||||||||
| - platform: template | ||||||||
| sensors: | ||||||||
| my_light_count: | ||||||||
| friendly_name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}" | ||||||||
|
|
||||||||
| template: | ||||||||
| # Existing modern template | ||||||||
| - binary_sensor: | ||||||||
| - name: Bright Outside | ||||||||
| state: "{{ states('sensor.lux_value') | float(0) > 10 }}" | ||||||||
| ``` | ||||||||
| {% endraw %} | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| To get started with the migration: | ||||||||
|
|
||||||||
| 1. Remove the `sensor` template definition from the `configuration.yaml` `sensor:` section. | ||||||||
|
|
||||||||
| Delete the following YAML from `configuration.yaml` file. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # Legacy template configuration | ||||||||
| - platform: template | ||||||||
| sensors: | ||||||||
| my_light_count: | ||||||||
| friendly_name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}" | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| Make sure to keep all the other platforms in the sensor section. Your `configuration.yaml` file would look like this after the change: | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
|
|
||||||||
| template: | ||||||||
| # Existing modern template | ||||||||
| - binary_sensor: | ||||||||
| - name: Bright Outside | ||||||||
| state: "{{ states('sensor.lux_value') | float(0) > 10 }}" | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| 1. Add the modern syntax provided by the repair. | ||||||||
|
|
||||||||
| The repair would provide the following YAML. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| template: | ||||||||
| - sensor: | ||||||||
| - default_entity_id: sensor.my_light_count | ||||||||
| name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| state: '{{ states.light | selectattr(''state'', ''eq'', ''on'') | list | count }}' | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| This YAML should be added to the `template:` section inside `configuration.yaml`. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: | ||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
|
|
||||||||
| template: | ||||||||
| # Existing modern template | ||||||||
| - binary_sensor: | ||||||||
| - name: Bright Outside | ||||||||
| state: "{{ states('sensor.lux_value') | float(0) > 10 }}" | ||||||||
|
|
||||||||
| # Copied example | ||||||||
| - sensor: | ||||||||
| - default_entity_id: sensor.my_light_count | ||||||||
| name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| state: '{{ states.light | selectattr(''state'', ''eq'', ''on'') | list | count }}' | ||||||||
| ``` | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| In this example, `configuration.yaml` already had a `template:` section. When copying the YAML, make sure to avoid adding double `template:` sections. | ||||||||
|
|
||||||||
| 1. Restart Home Assistant by going to **Settings** three dotted menu and selecting **Restart Home Assistant**. Or reload template entities by going to **Developer tools** **YAML** tab and selecting the **Template entities** reload button. | ||||||||
|
|
||||||||
| ### Migrating a sensor from an included file to an included file | ||||||||
|
|
||||||||
| This example covers how to migrate a legacy template sensor into modern syntax when the sensor exists in an included `sensors.yaml` file. | ||||||||
|
|
||||||||
| Take the example configuration. It's a configuration that is split between 3 files, `configuration.yaml`, `sensors.yaml`, and `templates.yaml`. | ||||||||
|
|
||||||||
| ```yaml | ||||||||
| # configuration.yaml | ||||||||
| sensor: !include sensors.yaml | ||||||||
| template: !include templates.yaml | ||||||||
| ``` | ||||||||
|
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # sensors.yaml | ||||||||
|
|
||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
|
|
||||||||
| # Legacy template configuration | ||||||||
| - platform: template | ||||||||
| sensors: | ||||||||
| my_light_count: | ||||||||
| friendly_name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}" | ||||||||
| ``` | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| # templates.yaml | ||||||||
|
|
||||||||
| # Existing modern template | ||||||||
| - binary_sensor: | ||||||||
| - name: Bright Outside | ||||||||
| state: "{{ states('sensor.lux_value') | float(0) > 10 }}" | ||||||||
| ``` | ||||||||
| {% endraw %} | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| To get started with the migration: | ||||||||
|
|
||||||||
| 1. Remove the `sensor` template definition from the `sensors.yaml` section. | ||||||||
|
|
||||||||
| Delete the following YAML from `sensors.yaml` file. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # Legacy template configuration | ||||||||
| - platform: template | ||||||||
| sensors: | ||||||||
| my_light_count: | ||||||||
| friendly_name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| value_template: "{{ states.light | selectattr('state', 'eq', 'on') | list | count }}" | ||||||||
| ``` | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
| Make sure to keep all the other platforms in the sensor file. Your `sensors.yaml` file would look like this after the change: | ||||||||
|
|
||||||||
|
|
||||||||
| ```yaml | ||||||||
| # sensors.yaml | ||||||||
|
|
||||||||
| # SNMP Configuration | ||||||||
| - platform: snmp | ||||||||
| host: 192.168.1.32 | ||||||||
| baseoid: 1.3.6.1.4.1.2021.10.1.3.1 | ||||||||
| ``` | ||||||||
|
|
||||||||
| 2. Add the modern syntax provided by the repair. | ||||||||
|
|
||||||||
| The repair would provide the following YAML. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| template: | ||||||||
| - sensor: | ||||||||
| - default_entity_id: sensor.my_light_count | ||||||||
| name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| state: '{{ states.light | selectattr(''state'', ''eq'', ''on'') | list | count }}' | ||||||||
| ``` | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
| This YAML should be added to the `templates.yaml` file. | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% raw %} | ||||||||
| ```yaml | ||||||||
| # templates.yaml | ||||||||
|
|
||||||||
| # Existing modern template | ||||||||
| - binary_sensor: | ||||||||
| - name: Bright Outside | ||||||||
| state: "{{ states('sensor.lux_value') | float(0) > 10 }}" | ||||||||
|
|
||||||||
| # Copied example | ||||||||
| - sensor: | ||||||||
| - default_entity_id: sensor.my_light_count | ||||||||
| name: Total lights on | ||||||||
| unique_id: sa892hfa9sdf8 | ||||||||
| state: '{{ states.light | selectattr(''state'', ''eq'', ''on'') | list | count }}' | ||||||||
| ``` | ||||||||
|
|
||||||||
c0ffeeca7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
| {% endraw %} | ||||||||
|
|
||||||||
| In this example, `configuration.yaml` already has a `template: !include templates.yaml`. When copying the yaml, make sure to avoid adding the `template:` section inside `templates.yaml`. | ||||||||
|
|
||||||||
| 1. Restart Home Assistant by going to **Settings** three dotted menu and selecting **Restart Home Assistant**. Or reload template entities by going to **Developer tools** **YAML** tab and selecting the **Template entities** reload button. | ||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.