core/homeassistant/components/template
akloeckner d20a620590
Make `this` variable available in template entities (#65201)
* feat: make this variable available in template entities

This makes the variable `this` available in template entities.
It will simplify the use of self-referencing template entities.
Because, without this, we have to repeat the entity id every time.
If we can solve this without explicitly spelling the entity id,
code can be re-used much better.

As a side-effect, this will allow to use `variables`-like patterns,
where attributes can be used as variables to calculate subsequent attributes or state.

Example:
```yaml
template:
  sensor:
    - name: test
      state: "{{ this.attributes.test }}"
      # not: "{{ state_attr('sensor.test', 'test' }}"
      attributes:
        test: "{{ now() }}"
```

* expose entity_id instead of this

* add test

* Refactor to expose this variable

* Tweak repr dunder

Co-authored-by: Erik <erik@montnemery.com>
2022-04-20 15:30:17 +02:00
..
__init__.py
alarm_control_panel.py
binary_sensor.py
button.py
config.py
const.py
cover.py
fan.py
light.py
lock.py
manifest.json
number.py
select.py
sensor.py
services.yaml
switch.py
template_entity.py Make `this` variable available in template entities (#65201) 2022-04-20 15:30:17 +02:00
trigger.py
trigger_entity.py
vacuum.py
weather.py