mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 01:06:52 +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 %}
|
||||
|
||||
### 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).
|
||||
|
@ -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 %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user