Template filter is_defined missing documentation (#21459)

This commit is contained in:
Jan Bouwhuis 2022-02-03 14:56:08 +01:00 committed by GitHub
parent 4e1aafa4ad
commit 9565d350bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -508,6 +508,20 @@ The temperature is 25°C
{% endraw %}
### Is defined
Sometimes a template should only return if a value or object is defined, if not, the supplied default value could be returned. This can be useful to validate a JSON payload.
The `is_defined` filter allows to throw an error if a value or object is not defined.
Example using `is_defined` to parse a JSON payload:
```text
{{ value_json.val | is_defined }}
```
This will throw an error `UndefinedError: 'value_json' is undefined` if the JSON payload has no `val` attribute.
### Distance
Not supported in [limited templates](#limited-templates).

View File

@ -187,7 +187,7 @@ unit_of_measurement:
required: false
type: string
value_template:
description: "Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract the value. Available variables: `entity_id`. The `entity_id` can be used to reference the entity's attributes."
description: "Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract the value. Available variables: `entity_id`. The `entity_id` can be used to reference the entity's attributes. If the template throws an error, the current state will be used instead."
required: false
type: template
{% endconfiguration %}