Skip to content

dht Device

Erik Baauw edited this page Sep 25, 2022 · 2 revisions

dht Device

A dht device exposes a DHTxx sensor connected to a single GPIO pin. I've tested with a DHT11 and with a DHT22 sensor. The DHT22 is not only more accurate, but seems to be a bit more stable as well. I understand other DHTxx sensors should work as well, as long as they use a single GPIO pin for data. Newer sensors that use I2C will not work.

Homebridge RPi configures the GPIO pin for input. Homebridge RPi configures the internal pull-up resister for the GPIO pin, so there's no need for an external pull-up resister. Homebridge RPi configures pigpiod to send real-time notifications when the GPIO state changes. Note however, that the sensor will only report data when triggered.

Homebridge RPi lowers the GPIO pin every 5 seconds, to trigger the sensor to send its data. The sensor flips the GPIO pin value, encoding 40 bits of data by changing the duration between these flips. The timing between these flips is handled by pigpiod, so any network delays shouldn't matter. After the data has been decoded correctly, Homebridge RPi updates the HomeKit values. Incorrect or incomplete data is silently ignored.

The device is exposed as a separate HomeKit accessory, with Temperature Sensor and Humidity Sensor services. Through these services, you can monitor the sensor temperature and humidity in HomeKit. The accessory mimics an Eve Weather, exposing a History service, so Eve shows the history of the temperature an humidity.

The dht device uses the following config.json keys:

key type Description
name string The name for the device in HomeKit.
gpio integer The GPIO pin.

Troubleshooting

Make sure the sensor has been connected correctly and is working properly, before filing an issue with Homebridge RPi. Best use the DHTXXD program from the pigpio examples to check that the sensor is reporting data:

$ DHTXXD -g17  
0 25.4 51.6

Note that the first 0 indicates success. If it reports another number, something went wrong.

Homebridge RPi should see the sensor data, even when the sensor is triggered by another progrem. The Homebridge log should see the following debug messages:

[9/25/2022, 5:31:07 PM] [RPi] pi10 Dht Temperature: gpio 23: DHTxx: temperature: 21.9, humidity: 49.8
[9/25/2022, 5:31:07 PM] [RPi] pi10 Dht Temperature: set Last Updated from "Sun Sep 25 2022 17:30:52" to "Sun Sep 25 2022 17:31:07"

When Homebridge RPi triggers the sensor, the Homebridge log shows the following debug messages:

[9/25/2022, 5:31:07 PM] [RPi] pi10: command WRITE (4) 23 0 ""
[9/25/2022, 5:31:07 PM] [RPi] pi10: command WRITE (4) => 0
[9/25/2022, 5:31:07 PM] [RPi] pi10: command MODES (0) 23 0 ""
[9/25/2022, 5:31:07 PM] [RPi] pi10: command MODES (0) => 0
[9/25/2022, 5:31:07 PM] [RPi] pi10: command PUD (2) 23 2 ""
[9/25/2022, 5:31:07 PM] [RPi] pi10: command PUD (2) => 0
[9/25/2022, 5:31:07 PM] [RPi] pi10 Dht Temperature: gpio 23: DHTxx: temperature: 21.9, humidity: 49.8
[9/25/2022, 5:31:07 PM] [RPi] pi10 Dht Temperature: set Last Updated from "Sun Sep 25 2022 17:30:52" to "Sun Sep 25 2022 17:31:07"

Set Log Level to 3 (on the accessory for the Pi) to see verbose debug messages of the GPIO state changes.