Skip to content

(RPi) Add DHT sensor to HAP

Amruth Pabba edited this page Jan 22, 2017 · 5 revisions

Hey, welcome to the DHT-based Temperature/Humidity Sensor tutorial!

This page has instructions on how to add a DHT Temperature Sensor to HomeKit.

This only works if you already have installed HAP-NodeJS. Also ensure that HAP-NodeJS isn't working when you are falling through this tutorial.

Only compatible with DHT11, DHT22, and AM2302

Ensure your sensor is wired up already. Power and Ground are straightforward, connect the sensor's data pin to Raspberry Pi Pin 7 (physical, not BCM).


The first command you want to run is: cd /home/pi/HAP-NodeJS/

This command takes you to HAP-NodeJS folder.


Run these commands:

sudo wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.50.tar.gz 
sudo tar zxvf bcm2835-1.50.tar.gz
cd bcm2835-1.50
./configure
make
sudo make check
sudo make install
cd ..
sudo rm -rf bcm2835*
sudo npm install node-gyp -g
sudo npm install nan
sudo npm install node-dht-sensor --unsafe-perm

These commands install all the prerequisites for the DHT-sensor linkup to HAP-NodeJS


The next command you want to run is: cd /home/pi/HAP-NodeJS/accessories

This command returns you to HAP-NodeJS accessories folder.


The next command you want to run is: sudo wget https://goo.gl/O3rxoK -O DHT_accessory.js

This command downloads the DHT Accessory file so that you can have the sensor work with HomeKit


Next you want to run this command: sudo nano DHT_accessory.js

This will open nano so that you can edit the DHT_accessory.js file.


Next you want to scroll down to change the first 4 lines to suit your configuration.

These lines are straightforward. You can change the HomeKit name, UUID, pin, and sensor type. The comments after each line help you customize the file.

Use this link to convert physical pin number to the BCM pin number: https://pinout.xyz/pinout/


Exit Nano once you are done customizing. You are done with adding your DHT-based sensor to HomeKit! Hope that helps and have fun with your new DIY HomeKit sensor!