From 5c6c7fe0b9b811b4ee9a7202869601796ff06c98 Mon Sep 17 00:00:00 2001 From: mertenats Date: Fri, 12 Aug 2016 08:31:39 +0200 Subject: [PATCH] Add a MQTT sensor example for a DHT22 sensor (#773) --- source/_components/sensor.mqtt.markdown | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source/_components/sensor.mqtt.markdown b/source/_components/sensor.mqtt.markdown index b64ed6d1c48..d1704a7bf07 100644 --- a/source/_components/sensor.mqtt.markdown +++ b/source/_components/sensor.mqtt.markdown @@ -61,3 +61,33 @@ sensor: value_template: {% raw %}'{{ value_json.batt }}'{% endraw %} ``` +### {% linkable_title Get temperature and humidity %} + +If you are using a DHT sensor and a NodeMCU board (esp8266), you can retrieve temperature and humidity with a MQTT sensor. A code example can be found [here](https://github.com/mertenats/open-home-automation/tree/master/ha_mqtt_sensor_dht22). A regular MQTT message from this example looks like this: + +``` +office/sensor1 + { + "temperature": 23.20, + "humidity": 43.70 + } +``` + +Then use this configuration example to extract the data from the payload: + +```yaml +# Example configuration.yml entry +sensor 1: + platform: mqtt + state_topic: 'office/sensor1' + name: 'Temperature' + unit_of_measurement: '°C' + value_template: '{{ value_json.temperature }}' + +sensor 2: + platform: mqtt + state_topic: 'office/sensor1' + name: 'Humidity' + unit_of_measurement: '%' + value_template: '{{ value_json.humidity }}' +```