Add a MQTT sensor example for a DHT22 sensor (#773)

This commit is contained in:
mertenats 2016-08-12 08:31:39 +02:00 committed by Fabian Affolter
parent 0a9336581e
commit 5c6c7fe0b9

View File

@ -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 }}'
```