mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 17:27:19 +00:00
Template filter is_defined
missing documentation (#21459)
This commit is contained in:
parent
4e1aafa4ad
commit
9565d350bd
@ -508,6 +508,20 @@ The temperature is 25°C
|
|||||||
|
|
||||||
{% endraw %}
|
{% 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
|
### Distance
|
||||||
|
|
||||||
Not supported in [limited templates](#limited-templates).
|
Not supported in [limited templates](#limited-templates).
|
||||||
|
@ -187,7 +187,7 @@ unit_of_measurement:
|
|||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
value_template:
|
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
|
required: false
|
||||||
type: template
|
type: template
|
||||||
{% endconfiguration %}
|
{% endconfiguration %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user