Add documentation on new template functions for devices (#18540)

* Add documentation on new template functions for devices

* fix examples

* Update docs

* rename function

* rename back

* Rename template function back
This commit is contained in:
Raman Gupta 2021-07-28 02:45:01 -04:00 committed by GitHub
parent 9d44781957
commit e784059e83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -18,6 +18,15 @@ The following describes trigger data associated with all platforms.
| `trigger.id` | Optional trigger `id`, or index of the trigger.
| `trigger.idx` | Index of the trigger.
### Device
| Template variable | Data |
| ---- | ---- |
| `trigger.platform` | Hardcoded: `device`.
| `trigger.event` | Event object that matched.
| `trigger.event.event_type` | Event type.
| `trigger.event.data` | Optional event data.
### Event
| Template variable | Data |

View File

@ -207,6 +207,31 @@ The same thing can also be expressed as a filter:
{% endraw %}
### Devices
- `device_entities(device_id)` returns a list of entities that are associated with a given device ID. Can also be used as a filter.
- `device_attr(device_or_entity_id, attr_name)` returns the value of `attr_name` for the given device or entity ID. Not supported in [limited templates](#limited-templates).
- `is_device_attr(device_or_entity_id, attr_name, attr_value)` returns whether the value of `attr_name` for the given device or entity ID matches `attr_value`. Not supported in [limited templates](#limited-templates).
- `device_id(entity_id)` returns the device ID for a given entity ID. Can also be used as a filter
#### Devices examples
{% raw %}
```text
{{ device_attr('deadbeefdeadbeefdeadbeefdeadbeef', 'manufacturer') }} # Sony
```
```text
{{ is_device_attr('deadbeefdeadbeefdeadbeefdeadbeef', 'manufacturer', 'Sony') }} # true
```
```text
{{ device_id('sensor.sony') }} # deadbeefdeadbeefdeadbeefdeadbeef
```
{% endraw %}
### Time
`now()` and `utcnow()` are not supported in [limited templates](#limited-templates).