From 98da394a611394f6f19072667d16a4f6513d2de4 Mon Sep 17 00:00:00 2001 From: R Huish Date: Tue, 6 Mar 2018 21:37:16 +0000 Subject: [PATCH] MQTT Sensor - JSON attributes example (#4755) * MQTT Sensor - JSON attributes example As per discusstions https://community.home-assistant.io/t/how-to-use-json-attributes-e-g-mqtt-sensor/40790/16 * Corrected Typo * Escaping --- source/_components/sensor.mqtt.markdown | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/source/_components/sensor.mqtt.markdown b/source/_components/sensor.mqtt.markdown index e6b96b3bc1d..aebe44beb99 100644 --- a/source/_components/sensor.mqtt.markdown +++ b/source/_components/sensor.mqtt.markdown @@ -82,6 +82,32 @@ json_attributes: In this section you find some real life examples of how to use this sensor. +### {% linkable_title JSON attributes configuration %} + +The example sensor below shows a configuration example which uses JSON in the state topic to add extra attributes. It also makes use of the availability topic. Attributes can then be extracted in [Templates](configuration/templating/#attributes); Example to extract data from the sensor below {% raw %}'{{ states.sensor.bs_client_name.attributes.ClientName }}'{% endraw %}. + +{% raw %} +```yaml +# Example configuration.yml entry +sensor: + - platform: mqtt + state_topic: "HUISHS/BunnyShed/NodeHealthJSON" + name: "BS RSSI" + unit_of_measurement: "dBm" + value_template: '{{ value_json.RSSI }}' + availability_topic: "HUISHS/BunnyShed/status" + payload_available: "online" + payload_not_available: "offline" + json_attributes: + - ClientName + - IP + - MAC + - RSSI + - HostName + - ConnectedSSID +``` +{% endraw %} + ### {% linkable_title 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: