mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-28 19:57:12 +00:00
MQTT Sensor: Warn about synchronization/double trigger issues. (#10262)
* Update sensor.mqtt.markdown Add a warning in the documentation that the state and attributes of a sensor will not change synchronously if they share the same MQTT topic and automations may be triggered twice. Reference closed issues #21699, and #21082. * Update sensor.mqtt.markdown formatting. * Update sensor.mqtt.markdown formatting. * Fix anchor * No double space after period. * ✏️ Tweak
This commit is contained in:
parent
eea9fdd6e1
commit
e4ba940729
@ -73,7 +73,7 @@ payload_not_available:
|
||||
type: string
|
||||
default: offline
|
||||
json_attributes_topic:
|
||||
description: The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes.
|
||||
description: The MQTT topic subscribed to receive a JSON dictionary payload and then set as sensor attributes. Implies `force_update` of the current sensor state when a message is received on this topic.
|
||||
required: false
|
||||
type: string
|
||||
json_attributes_template:
|
||||
@ -171,6 +171,8 @@ sensor:
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
The state and the attributes of the sensor by design do not update in a synchronous manner if they share the same MQTT topic. Temporal mismatches between the state and the attribute data may occur if both the state and the attributes are changed simultaneously by the same MQTT message. An automation that triggers on any state change of the sensor will also trigger both on the change of the state or a change of the attributes. Such automations will be triggered twice if both the state and the attributes change. Please use a [MQTT trigger](/docs/automation/trigger/#mqtt-trigger) and process the JSON in the automation directly via the {% raw %}`{{ trigger.payload_json }}`{% endraw %} [trigger data](/docs/automation/templating/#mqtt) for automations that must synchronously handle multiple JSON values within the same MQTT message.
|
||||
|
||||
### Get battery level
|
||||
|
||||
If you are using the [OwnTracks](/components/device_tracker.owntracks/) and enable the reporting of the battery level then you can use a MQTT sensor to keep track of your battery. A regular MQTT message from OwnTracks looks like this:
|
||||
|
Loading…
x
Reference in New Issue
Block a user