I have quite a few components that are duplicates of each other, but track different metrics/people.
An example of this is a template sensor that tracks the distance of Person A from home, and another that tracks Person B. Both have the same template logic behind them apart from a single line used to distinguish who to track:
{%- set name = "Person A" -%}
{{ distance(states.device_tracker[name|lower|replace(" ", "_")]) }}
Unfortunately, because of that single set name
line, it is not possible to use an !include
to reference a single YAML file for both sensors. It would be great, if possible, to pull the actual name (or friendly_name) of the sensor definition through, so that this could be used within the template (and then I can use a single YAML include across both, or more). This would behave similar to triggers.
- platform: template
sensors:
person_a_distance:
value_template: "{{ distance(states.device_tracker[definition.object_id.split("_")[:-1]]) }}"