just like we can use and set those on Sensor and Binary_sensor. or an attribute_templates,as allowed for the legacy format templates
unfortunately:
Invalid config for [cover.template]: [attribute_templates] is an invalid option for [cover.template]. Check: cover.template->covers->rolluik_studenten_template->attribute_templates. (See ?, line ?).
Combined with the new this
variable, an attribute, in below use case for id
, would allow us to completely copy a full entity config, and fill out the essential id automatically, using a yaml anchor.
Compare the strength of that in a template sensor like:
template:
- sensor:
- unique_id: dark_sky_forecast_0
<<: &config_dsf
name: >
{% set id = this.attributes.get('id',0) %}
{{as_timestamp(now() + timedelta(days=id|int(default=0)),none)|timestamp_custom('%a %-d %b',default="Not yet set")}}: {{
states('sensor.dark_sky_forecast_icon_'~id~'d').replace('-',' ')|capitalize}}
state: >
{% set id = this.attributes.get('id',0) %}
{{- states('sensor.dark_sky_forecast_daytime_high_temperature_'~id~'d')}}°/
{{- states('sensor.dark_sky_forecast_overnight_low_temperature_'~id~'d')}}°/
{{- states('sensor.dark_sky_forecast_precip_probability_'~id~'d')}}%
picture: >
{% set id = this.attributes.get('id',0) %}
{{'/local/weather/icons/' ~ states('sensor.dark_sky_forecast_icon_'~id~'d') ~ '.png'}}
attributes:
id: 0
- unique_id: dark_sky_forecast_1
<<: *config_dsf
attributes:
id: 1
- unique_id: dark_sky_forecast_2
<<: *config_dsf
attributes:
id: 2
and now for the Template cover, which we can Not use an attribute, and as a consequence need to copy the full config for all Covers:
cover:
- platform: template
covers:
rolluik_voorkamer_template:
unique_id: rolluik_voorkamer_template
device_class: shutter
friendly_name: Rolluik voorkamer template
open_cover:
service: cover.open_cover
target: &voor
entity_id: >
{% set id = 'voorkamer' %}
{% set silent = states('input_boolean.discrete_covers') %}
{% if silent == 'on' %} cover.rolluik_{{id}}_low_speed
{% else %} cover.rolluik_{{id}}
{% endif %}
position_template: >
{% set id = 'voorkamer' %}
{{state_attr('cover.rolluik_'~id,'current_position')}}
close_cover:
service: cover.close_cover
target: *voor
stop_cover:
service: cover.stop_cover
target: *voor
set_cover_position:
service: cover.set_cover_position
target: *voor
data:
position: '{{position}}'
availability_template: >
{% set id = 'voorkamer' %}
{{state_attr('cover.rolluik_'~id,'current_position')|is_number}}
rolluik_logeerkamer_template:
unique_id: rolluik_logeerkamer_template
device_class: shutter
friendly_name: Rolluik logeerkamer template
open_cover:
service: cover.open_cover
target: &logeer
entity_id: >
{% set id = 'logeerkamer' %}
{% set silent = states('input_boolean.discrete_covers') %}
{% if silent == 'on' %} cover.rolluik_{{id}}_low_speed
{% else %} cover.rolluik_{{id}}
{% endif %}
position_template: >
{% set id = 'logeerkamer' %}
{{state_attr('cover.rolluik_'~id,'current_position')}}
close_cover:
service: cover.close_cover
target: *logeer
stop_cover:
service: cover.stop_cover
target: *logeer
set_cover_position:
service: cover.set_cover_position
target: *logeer
data:
position: '{{position}}'
availability_template: >
{% set id = 'logeerkamer' %}
{{state_attr('cover.rolluik_'~id,'current_position')|is_number}}
thanks for considering