I’ve made a bunch of template covers to be able to add some smart functionality to my outdoor vertical awnings. I have an AppDaemon app that listens for events for these covers (e.g. open, close, stop) so that I can override them in different ways, e.g. if it’s been raining and they’ve gotten wet, keep them in their current state so they can dry, keep them rolled down while the TV is on to avoid glare etc.
I have a couple of them and don’t seem to be able to use YAML anchors for them due to the entity in the event being sent. I’ve tried adding an extra field in the template like this:
living_room_bottom_screen: &smart_screen
entity: cover.living_room_bottom_screen
friendly_name: "Living Room Bottom Screen"
unique_id: cover-living_room_bottom_screen
position_template: "{{ state_attr('cover.hidden_living_room_bottom_screen', 'current_position') | int }}"
device_class: shade
open_cover:
event: SMART_SCREEN_OPEN
event_data:
entity: "{{ entity }}"
close_cover:
event: SMART_SCREEN_CLOSE
event_data:
entity: "{{ entity }}"
stop_cover:
event: SMART_SCREEN_STOP
event_data:
entity: "{{ entity }}"
set_cover_position:
event: SMART_SCREEN_SET_POSITION
event_data:
entity: "{{ entity }}"
position: "{{ position }}"
living_room_west_screen:
<<: *smart_screen
entity: cover.living_room_west_screen
friendly_name: "Living Room West Screen"
unique_id: cover-living_room_west_screen
but get the following error in HA:
So I’ve basically had to copy-paste everything for each cover and just hope that I haven’t missed replacing one of the fields to the correct entity name:
living_room_bottom_screen:
friendly_name: "Living Room Bottom Screen"
unique_id: cover-living_room_bottom_screen
position_template: "{{ state_attr('cover.hidden_living_room_bottom_screen', 'current_position') | int }}"
device_class: shade
open_cover:
event: SMART_SCREEN_OPEN
event_data:
entity: cover.living_room_bottom_screen
close_cover:
event: SMART_SCREEN_CLOSE
event_data:
entity: cover.living_room_bottom_screen
stop_cover:
event: SMART_SCREEN_STOP
event_data:
entity: cover.living_room_bottom_screen
set_cover_position:
event: SMART_SCREEN_SET_POSITION
event_data:
entity: cover.living_room_bottom_screen
position: "{{ position }}"
living_room_top_south_screen:
friendly_name: "Living Room Top South Screen"
unique_id: cover-living_room_top_south_screen
position_template: "{{ 100 - state_attr('cover.hidden_living_room_top_south_screen', 'current_position') | int }}"
device_class: shade
open_cover:
event: SMART_SCREEN_OPEN
event_data:
entity: cover.hidden_living_room_top_south_screen
close_cover:
event: SMART_SCREEN_CLOSE
event_data:
entity: cover.hidden_living_room_top_south_screen
stop_cover:
event: SMART_SCREEN_STOP
event_data:
entity: cover.hidden_living_room_top_south_screen
set_cover_position:
event: SMART_SCREEN_SET_POSITION
event_data:
entity: cover.hidden_living_room_top_south_screen
position: "{{ 100 - position }}"
living_room_west_screen:
friendly_name: "Living Room West Screen"
unique_id: cover-living_room_west_screen
position_template: "{{ 100 - state_attr('cover.hidden_living_room_west_screen', 'current_position') | int }}"
device_class: shade
open_cover:
event: SMART_SCREEN_OPEN
event_data:
entity: cover.living_room_west_screen
close_cover:
event: SMART_SCREEN_CLOSE
event_data:
entity: cover.living_room_west_screen
stop_cover:
event: SMART_SCREEN_STOP
event_data:
entity: cover.living_room_west_screen
set_cover_position:
event: SMART_SCREEN_SET_POSITION
event_data:
entity: cover.living_room_west_screen
position: "{{ 100 - position }}"
office_screen:
friendly_name: "Office Screen"
unique_id: cover-office_screen
position_template: "{{ 100 - state_attr('cover.hidden_office_screen', 'current_position') | int }}"
device_class: shade
open_cover:
event: SMART_SCREEN_OPEN
event_data:
entity: cover.office_screen
close_cover:
event: SMART_SCREEN_CLOSE
event_data:
entity: cover.office_screen
stop_cover:
event: SMART_SCREEN_STOP
event_data:
entity: cover.office_screen
set_cover_position:
event: SMART_SCREEN_SET_POSITION
event_data:
entity: cover.office_screen
position: "{{ 100 - position }}"
(For those wondering, the position inversion on some covers is intended/correct)
Is there any way to do this cleaner?