Continuing the discussion from WTH, no global entity variables in template sensors?:
imagine we could replace the days=0 here, and then simply jot the whole template in an anchor and be done with it for days 0 - 5 .
- unique_id: dark_sky_forecast_0
name: >
{{as_timestamp(now() + timedelta(days=0),none)|timestamp_custom('%a %-d %b',default='Not yet set')}}: {{
states('sensor.dark_sky_forecast_icon_0d').replace('-',' ')|capitalize}}
state: >
{{- states('sensor.dark_sky_forecast_daytime_high_temperature_0d')|round(0)}}°/
{{- states('sensor.dark_sky_forecast_overnight_low_temperature_0d')|round(0)}}°/
{{- states('sensor.dark_sky_forecast_precip_probability_0d')|round(0)}}%
picture: >
{{'/local/weather/icons/' ~ states('sensor.dark_sky_forecast_icon_0d') ~ '.png'}}
by using:
- unique_id: dark_sky_forecast_0
variables:
day: 0
name: >
or:
replace:
- unique_id: composite_me_location
name: Me location
state: >
{% set id = 'me' %}
{{states('device_tracker.'~id~'_app')}}
picture: >
{% set id = 'me' %}
/local/family/{{id}}_home.png
attributes:
location: >
{% set id = 'me' %}
{% set sensor = 'sensor.'~id~'_app_geocoded_location' %}
{{state_attr(sensor,'Name')}} {{state_attr(sensor,'Postal Code')}} {{state_attr(sensor,'Locality')}} {{state_attr(sensor,'Country')}}
country_code: >
{% set id = 'me' %}
{{state_attr('sensor.'~id~'_app_geocoded_location','ISO Country Code')|lower}}
country: >
{% set id = 'me' %}
{{state_attr('sensor.'~id~'_app_geocoded_location','Country')}}
latitude: >
{% set id = 'me' %}
{% set sensor = 'sensor.'~id~'_app_geocoded_location' %}
{{state_attr(sensor,'Location')[0]}}
longitude: >
{% set id = 'me' %}
{% set sensor = 'sensor.'~id~'_app_geocoded_location' %}
{{state_attr(sensor,'Location')[1]}}
with:
- unique_id: composite_me_location
variables:
id: me
<<: &location_anchor
name: >
{{id}} location
state: >
{{states('device_tracker.'~id~'_app')}}
picture: >
/local/family/{{id}}_home.png
attributes:
location: >
{% set sensor = 'sensor.'~id~'_app_geocoded_location' %}
{{state_attr(sensor,'Name')}} {{state_attr(sensor,'Postal Code')}} {{state_attr(sensor,'Locality')}} {{state_attr(sensor,'Country')}}
country_code: >
{{state_attr('sensor.'~id~'_app_geocoded_location','ISO Country Code')|lower}}
country: >
{{state_attr('sensor.'~id~'_app_geocoded_location','Country')}}
latitude: >
{% set sensor = 'sensor.'~id~'_app_geocoded_location' %}
{{state_attr(sensor,'Location')[0]}}
longitude: >
{% set sensor = 'sensor.'~id~'_app_geocoded_location' %}
{{state_attr(sensor,'Location')[1]}}
# and here comes the true advantage of it:
- unique_id: composite_she_location
variables:
id: she
<<: *location_anchor