Skip to content

Improve MQTT template docs on handling null values #38485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/_docs/configuration/templating.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/_integrations/sensor.mqtt.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down