Add label template functions (#32122)

* Add label template functions

* tiny tweaks

---------

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
This commit is contained in:
Franck Nijhof 2024-04-02 09:54:09 +02:00 committed by GitHub
parent 82762d63da
commit 439b5f430b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -574,6 +574,59 @@ If there is more than one entry with the same title, the entities for all the ma
{% endraw %} {% endraw %}
### Labels
- `labels()` returns the full list of label IDs, or those for a given area ID, device ID, or entity ID.
- `label_id(lookup_value)` returns the label ID for a given label name.
- `label_name(lookup_value)` returns the label name for a given label ID.
- `label_areas(label_name_or_id)` returns the list of area IDs tied to a given label ID or name.
- `label_devices(label_name_or_id)` returns the list of device IDs tied to a given label ID or name.
- `label_entities(label_name_or_id)` returns the list of entity IDs tied to a given label ID or name.
Each of the label template functions can also be used as a filter.
#### Labels examples
{% raw %}
```text
{{ labels() }} # ['christmas_decorations', 'energy_saver', 'security']
```
```text
{{ labels("living_room") }} # ['christmas_decorations', 'energy_saver']
```
```text
{{ labels("my_device_id") }} # ['security']
```
```text
{{ labels("light.christmas_tree") }} # ['christmas_decorations']
```
```text
{{ label_id('Energy saver') }} # 'energy_saver'
```
```text
{{ label_name('energy_saver') }} # 'Energy saver'
```
```text
{{ label_areas('security') }} # ['driveway', 'garden', 'porch']
```
```text
{{ label_devices('energy_saver') }} # ['deadbeefdeadbeefdeadbeefdeadbeef']
```
```text
{{ label_entities('security') }} # ['camera.driveway', 'binary_sensor.motion_garden', 'camera.porch']
```
{% endraw %}
### Issues ### Issues
- `issues()` returns all open issues as a mapping of (domain, issue_id) tuples to the issue object. - `issues()` returns all open issues as a mapping of (domain, issue_id) tuples to the issue object.