Closed deepcoder closed 4 years ago
Hey there @home-assistant/core, @emontnemery, mind taking a look at this issue as its been labeled with a integration (mqtt
) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)
As explained in the docs, https://www.home-assistant.io/integrations/sensor.mqtt/#json_attributes_topic, the attributes must be a valid json dictionary.
If you want to extract only battery level as an attribute, use a template like this:
json_attributes_template: '{{ {"battery": value_json.battery } | tojson }}'
Thank you very much for the correct syntax example! The syntax examples cited in the documentation did not work for me, for example : "{{ value_json.batt }}" of the 'GET BATTERY LEVEL' example at https://www.home-assistant.io/integrations/sensor.mqtt/#json_attributes_topic . The format of the mqtt message in this example was very similar to my message, with no multi level hierarchy.
The Jinja syntax seems to be an ART and science!!
Again thank you very much for your answer and work!!!!
The documentation is maybe confusing, the "GET BATTERY LEVEL" example is about using the battery level as the sensor state, not as an attribute. Maybe that chapter should instead be called "Using JSON dict key as sensor state" or something like that?
Please help by reviewing this update of the configuration: home-assistant/home-assistant.io/pull/13382
Problem with MQTT sensor JSON parsing in transition from 'json_attributes:' to 'json_attributes_template'
Not able to get 'json_attributes_template:' to extract subset of attributes in JSON string referenced by 'json_attributes_topic:'
Throws this warning and no attributes are added to the MQTT sensor:
'WARNING (MainThread) [homeassistant.components.mqtt] JSON result was not a dictionary'
JSON string that is being parsed:
b'{"timestamp":"20200509001056", "mac-address":"3F:46:0D:90:F0:14","rssi":-81, "temperature":90.4, "humidity":47.5, "battery":100, "sensor-name":"Govee_H5052_F014"}'
see example yaml from sensor section of configuration below.
0.109.6 in docker container running on raspberry pi 3
Problem-relevant
configuration.yaml
Traceback/Error logs
Additional information