HomeKit DHT22
An Apple HomeKit accessory for the DHT22 temperature and humidity sensor running on a Raspberry Pi.

Dependencies
- Go - this accessory is written in Go
- HomeControl - to expose climate readings from the Enviro+ as an Apple HomeKit accessory
- climate-sensor - to read the DHT22 sensor and export it for scraping by Prometheus
Installation
Install this on a Raspberry Pi, or test it on macOS.
Setup
- Install Go >= 1.14 (useful Gist for Raspberry Pi)
- Clone this project:
git clone https://github.com/sighmon/homekit-dht22 and then cd homekit-dht22
- Install the Go dependencies:
go get
- Install and run the Climate Sensor exporter climate-sensor
Build
- To build this accessory:
go build homekit-dht22.go
- To cross-compile for Raspberry Pi on macOS:
env GOOS=linux GOARCH=arm GOARM=7 go build homekit-dht22.go
Run
- Execute the executable:
./homekit-dht22
- Or run with the command:
go run homekit-dht22.go
Start automatically at boot
- sudo cp homekit-dht22.service /lib/systemd/system/homekit-dht22.service
- sudo systemctl daemon-reload
- sudo systemctl enable homekit-dht22.service
- sudo systemctl start homekit-dht22.service
Optional flags
The flag defaults can be overridden by handing them in at runtime:
-host=http://0.0.0.0 The host of your DHT22 sensor
-port=1006 The port of your DHT22 sensor
-sleep=5s The time between updating the accessory with sensor readings (5s equals five seconds)
-dev This turns on development mode to return a random temperature reading without needing to have a DHT22
e.g. to override the port run: go run homekit-dht22.go -port=8000 or ./homekit-dht22 -port=8000
Reset this accessory
If you uninstall this accessory from your Apple Home, you'll also need to delete the stored data for it to be able to be re-added.
macOS
- Delete the data in the folder created:
homekit-dht22/DHT22/
- Restart the executable
Raspberry Pi
- Remove the persistent data:
rm -rf /var/lib/homekit-dht22/data
- Restart the Raspberry Pi
Thanks
This project uses the amazing work of Matthias. Please consider donating if you found this useful.