diff --git a/source/_docs/configuration/templating.markdown b/source/_docs/configuration/templating.markdown index 3ca23e2808d..249ff8a54da 100644 --- a/source/_docs/configuration/templating.markdown +++ b/source/_docs/configuration/templating.markdown @@ -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). diff --git a/source/_integrations/sensor.mqtt.markdown b/source/_integrations/sensor.mqtt.markdown index c529e87481d..e50a55a4bf0 100644 --- a/source/_integrations/sensor.mqtt.markdown +++ b/source/_integrations/sensor.mqtt.markdown @@ -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 %}