Improve MQTT template docs on handling null values (#38485)

This commit is contained in:
Jan Bouwhuis 2025-04-12 06:44:27 +02:00 committed by GitHub
parent a92290d6c6
commit 4144b06385
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -1636,11 +1636,13 @@ Example value template:
With given payload:
```json
{ "state": "ON", "temperature": 21.902 }
{ "state": "ON", "temperature": 21.902, "humidity": null }
```
Template {% raw %}`{{ value_json.temperature | round(1) }}`{% endraw %} renders to `21.9`.
Template {% raw %}`{{ value_json.humidity }}`{% endraw %} renders to `None`.
{% endnote %}
#### Using command templates with MQTT

View File

@ -201,7 +201,7 @@ state_class:
required: false
type: string
state_topic:
description: The MQTT topic subscribed to receive sensor values. If `device_class`, `state_class`, `unit_of_measurement` or `suggested_display_precision` is set, and a numeric value is expected, an empty value `''` will be ignored and will not update the state, a `'null'` value will set the sensor to an `unknown` state. The `device_class` can be `null`.
description: The MQTT topic subscribed to receive sensor values. If `device_class`, `state_class`, `unit_of_measurement` or `suggested_display_precision` is set, and a numeric value is expected, an empty value `''` will be ignored and will not update the state, a `'None'` value will set the sensor to an `unknown` state. If a `value_template` is used to parse a JSON payload, a `null` value in the JSON [will be rendered as]((/docs/configuration/templating/#using-value-templates-with-mqtt)) `'None'`. Note that the `device_class` can be `null`.
required: true
type: string
unique_id: