Document this variable in state-based template entities (#22211)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Erik Montnemery 2022-04-20 15:35:07 +02:00 committed by GitHub
parent 4ece5bfa96
commit 5bdd871e4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 0 deletions

View File

@ -111,6 +111,10 @@ panels:
default: number
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.
## Considerations
If you are using the state of an integration that takes extra time to load, the Template Alarm Control Panel may get an `unknown` state during startup. This results in error messages in your log file until that integration has completed loading. If you use `is_state()` function in your template, you can avoid this situation.

View File

@ -114,6 +114,10 @@ cover:
type: template
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.
## Considerations
If you are using the state of a platform that takes extra time to load, the

View File

@ -134,6 +134,10 @@ fan:
default: 100
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.
## Converting from speeds to percentage
When converting a fan with 3 speeds from the old fan entity model, the following percentages can be used:

View File

@ -179,6 +179,10 @@ light:
type: action
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.
## Considerations
If you are using the state of a platform that takes extra time to load, the

View File

@ -75,6 +75,10 @@ lock:
default: false
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.
## Considerations
If you are using the state of a platform that takes extra time to load, the Template Lock may get an `unknown` state during startup. This results in error messages in your log file until that platform has completed loading. If you use `is_state()` function in your template, you can avoid this situation. For example, you would replace {% raw %}`{{ state('switch.source') == 'on') }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an unknown result: {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}

View File

@ -82,6 +82,10 @@ switch:
type: template
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.
## Considerations
If you are using the state of a platform that takes extra time to load, the Template Switch may get an `unknown` state during startup. This results in error messages in your log file until that platform has completed loading. If you use `is_state()` function in your template, you can avoid this situation. For example, you would replace {% raw %}`{{ states.switch.source.state == 'on') }}`{% endraw %} with this equivalent that returns `true`/`false` and never gives an unknown result: {% raw %}`{{ is_state('switch.source', 'on') }}`{% endraw %}

View File

@ -68,6 +68,10 @@ template:
{% endraw %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](#self-referencing) of an entity's state and attribute in templates.
## Trigger-based template binary sensors, buttons, numbers, selects and sensors
If you want more control over when an entity updates, you can define a trigger. Triggers follow the same format and work exactly the same as [triggers in automations][trigger-doc]. This feature is a great way to create entities based on webhook data ([example](#storing-webhook-information)), or update entities based on a schedule.
@ -564,6 +568,24 @@ template:
{% endraw %}
### Self referencing
This example demonstrates how the `this` variable can be used in templates for self-referencing.
{% raw %}
```yaml
template:
- sensor:
- name: test
state: "{{ this.attributes.test }}"
# not: "{{ state_attr('sensor.test', 'test' }}"
attributes:
test: "{{ now() }}"
```
{% endraw %}
## Legacy binary sensor configuration format
_This format still works but is no longer recommended. [Use modern configuration](#configuration-variables)._

View File

@ -103,6 +103,10 @@ vacuum:
type: [string, list]
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.
## Examples
### Control vacuum with Harmony Hub

View File

@ -87,3 +87,7 @@ forecast_template:
required: false
type: template
{% endconfiguration %}
### Template variables
State-based template entities have the special template variable `this` available in their templates. The `this` variable aids [self-referencing](/integrations/template#self-referencing) of an entity's state and attribute in templates.