Hello,
I have a MQTT Message with a JSON string inside:
{
"0": {
"name": "",
"value": 1902
}
}
From this I want to have the “value”.
I made a mqtt sensor like this:
sensor:
- name: "RPM Ventilation"
state_topic: "device/message"
value_template: "{{ value_json.0.value }}"
But I get only “unknown” in the entity and this error message in the log:
Template variable error: dict object has no element 0 when rendering '{{ value_json.0.value }}'
If I send a manual message with “test” instead of “0” everything works as expected:
MQTT message:
{
"test": {
"name": "",
"value": 1902
}
}
Sensor:
sensor:
- name: "RPM Ventilation"
state_topic: "device/message"
value_template: "{{ value_json.test.value }}"
→ Entity “RPM Ventilation” has 1902 as value.
Why is “0” so difficult to process and where is this behavior described and how I can get this working?