Hi all,
I am not sure how to migrate away from legacy templates, as I am not sure how to interpret the note:
“Note: If there are any existing template: sections in your configuration, make sure to omit the template: line from the yaml above. There can only be 1 template: section in configuration.yaml. Also, ensure the indentation is aligned with the existing entities within the template: section.”
Right now I have the following in my configuration.yaml
light: !include_dir_merge_list lights
switch: !include_dir_merge_list switches
Then in those folders (lights and switches) there is one file in each folder, called:
- virtual_lights.yaml
- virtual_switches.yaml
In each of them thse is (respectively) a section called
-
platform: template
switches:
… -
platform: template
lights:
…
which I will migrate to (respectively)
template:
- switch1:
… - switch2:
…
template:
- light1:
… - light2:
…
However both files will be included in the configuration.yaml file - if they are, in my understanding there will be two files with the “template” section, which is forbidden. What should I do then?
Should I replace:
light: !include_dir_merge_list lights
switch: !include_dir_merge_list switches
with:
template: !include_dir_merge_list templates
and define all templates in the templates directory with:
virtual_switches.yaml:
- switch1:
… - switch2:
…
virtual_lights.yaml:
- light1:
… - light2:
…
?
For context here these are example for virtual devices that I then make available externally to sync with another system as Matter defvides. Here is how it now looks like:
virtual_switches.yaml:
- platform: template
switches:
adl_default_config_virtual_switch:
unique_id: adl_default_config_virtual_switch
friendly_name: "ADL Default Config"
value_template: >
{{ is_state('switch.adaptive_lighting_default_config', 'on') }}
turn_on:
service: switch.turn_on
target:
entity_id: switch.adaptive_lighting_default_config
turn_off:
service: switch.turn_off
target:
entity_id: switch.adaptive_lighting_default_config
adl_sleep_mode_virtual_switch:
unique_id: adl_sleep_mode_virtual_switch
friendly_name: "ADL Sleep Mode: Default Config"
value_template: >
{{ is_state('switch.adaptive_lighting_sleep_mode_default_config', 'on') }}
turn_on:
service: switch.turn_on
target:
entity_id: switch.adaptive_lighting_sleep_mode_default_config
turn_off:
service: switch.turn_off
target:
entity_id: switch.adaptive_lighting_sleep_mode_default_config
virtual_lights.yaml:
- platform: template
lights:
adl_max_brightness_virtual_light:
unique_id: "adl_max_brightness_virtual_light"
friendly_name: "ADL Max Brightness Virtual Light"
value_template: "{{ states('input_number.adl_max_brightness') | int > 0 }}"
level_template: "{{ (states('input_number.adl_max_brightness') | int * 255 / 100) | int }}"
set_level:
service: input_number.set_value
target:
entity_id: input_number.adl_max_brightness
data:
value: "{{ (brightness | int * 100 / 255) | round(0) }}"
turn_on:
service: input_number.set_value
target:
entity_id: input_number.adl_max_brightness
data:
value: 50
turn_off:
service: input_number.set_value
target:
entity_id: input_number.adl_max_brightness
data:
value: 0
adl_min_brightness_virtual_light:
unique_id: "adl_min_brightness_virtual_light"
friendly_name: "ADL Min Brightness Virtual Light"
value_template: "{{ states('input_number.adl_min_brightness') | int > 0 }}"
level_template: "{{ (states('input_number.adl_min_brightness') | int * 255 / 100) | int }}"
set_level:
service: input_number.set_value
target:
entity_id: input_number.adl_min_brightness
data:
value: "{{ (brightness | int * 100 / 255) | round(0) }}"
turn_on:
service: input_number.set_value
target:
entity_id: input_number.adl_min_brightness
data:
value: 50
turn_off:
service: input_number.set_value
target:
entity_id: input_number.adl_min_brightness
data:
value: 0
Thank you