Add reference to context in automation templating (#19043)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Jamie Weston 2021-09-05 00:00:23 +01:00 committed by GitHub
parent c81baaf834
commit 32e20dfaaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -9,7 +9,7 @@ The template variable `this` is also available when evaluating any `trigger_vari
## Available this Data
`this` is a state object. [State Objects](/docs/configuration/state_object) provides a comprehensive description for the properties of `this` and `this.attributes`.
Variable `this` is the [state object](/docs/configuration/state_object) of the automation. State objects also contain context data which can be used to identify the user that caused a script or automation to execute.
## Available Trigger Data

View File

@ -19,6 +19,9 @@ All states will always have an entity id, a state and a timestamp when last upda
| `state.last_updated` | Time the state was written to the state machine in UTC time. Note that writing the exact same state including attributes will not result in this field being updated. Example: `2017-10-28 08:13:36.715874+00:00`. |
| `state.last_changed` | Time the state changed in the state machine in UTC time. This is not updated when there are only updated attributes. Example: `2017-10-28 08:13:36.715874+00:00`. |
| `state.attributes` | A dictionary with extra attributes related to the current state. |
| `state.context` | A dictionary with extra attributes related to the context of the state. |
## Attributes
The attributes of an entity are optional. There are a few attributes that are used by Home Assistant for representing the entity in a specific way. Each integration will also have its own attributes to represent extra state data about the entity. For example, the light integration has attributes for the current brightness and color of the light. When an attribute is not available, Home Assistant will not write it to the state.
@ -33,3 +36,13 @@ When using templates, attributes will be available by their name. For example `s
| `unit_of_measurement` | The unit of measurement the state is expressed in. Used for grouping graphs or understanding the entity. Example: `°C`. |
When an attribute contains spaces, you can retrieve it like this: `state_attr('sensor.livingroom', 'Battery numeric')`.
## Context
Context is used to tie events and states together in Home Assistant. Whenever an automation or user interaction causes states to change, a new context is assigned. This context will be attached to all events and states that happen as result of the change.
| Field | Description |
| ----- | ------------------------------------------------------------------- |
| context_id | Unique identifier for the context. |
| user_id | Unique identifier of the user that started the change. Will be `None` if action was not started by a user (ie. started by an automation) |
| parent_id | Unique identifier of the parent context that started the change, if available. For example, if an automation is triggered, the context of the trigger will be set as parent. |