{"id":21333592,"url":"https://github.com/ptr33/temp_humidity_sensor","last_synced_at":"2026-05-08T10:31:35.522Z","repository":{"id":263293931,"uuid":"884797435","full_name":"ptr33/temp_humidity_sensor","owner":"ptr33","description":"Temperature and Humidity Sensor with a DHT22 and Raspberry Pi Zero W and publish to MQTT","archived":false,"fork":false,"pushed_at":"2024-11-17T15:38:47.000Z","size":2501,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-21T03:24:57.852Z","etag":null,"topics":["dht22","homeassistant","humidity-sensor","mqtt","raspberry-pi-zero-w","rasperry-pi","temperature-sensor"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ptr33.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-07T12:08:39.000Z","updated_at":"2024-11-12T11:50:10.000Z","dependencies_parsed_at":"2024-11-17T17:21:37.185Z","dependency_job_id":null,"html_url":"https://github.com/ptr33/temp_humidity_sensor","commit_stats":null,"previous_names":["ptr33/temp_humidity_sensor"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ptr33/temp_humidity_sensor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptr33%2Ftemp_humidity_sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptr33%2Ftemp_humidity_sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptr33%2Ftemp_humidity_sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptr33%2Ftemp_humidity_sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ptr33","download_url":"https://codeload.github.com/ptr33/temp_humidity_sensor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptr33%2Ftemp_humidity_sensor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32776527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dht22","homeassistant","humidity-sensor","mqtt","raspberry-pi-zero-w","rasperry-pi","temperature-sensor"],"created_at":"2024-11-21T23:13:29.395Z","updated_at":"2026-05-08T10:31:35.512Z","avatar_url":"https://github.com/ptr33.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Temperature and Humidty Sensor\nThis project uses a DHT22 sensor connected to a Raspberry Pi Zero W to capture temperature and humidity measurements. The information is published over WLAN to a [MQTT](https://mqtt.org/) broker and displayed in [Homeassistant](https://www.home-assistant.io/).\n\nThe configuration of this MQTT client and topics should be set in \n[config.json](https://github.com/ptr33/temp_humidity_sensor/blob/main/config.json).\nAn offset to compensate self-heating of the Raspberry Pi can be set with *offset_temperature* and *offset_humidity*.\nA MQTT broker should already be running - example in https://mosquitto.org/\n\n![homeassistant view](img/homeassistant.png)\n\n\n## References\n\nInitial work from\n- https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code/tree/legacy/Adafruit_DHT_Driver\n- https://www.airspayce.com/mikem/bcm2835/\n\n\n## Raspberry PI Zero W setup\n\nCreate an image with [Raspberry PI Imaging Utility](https://www.raspberrypi.com/news/raspberry-pi-imager-imaging-utility/).\nSetup hostname, wifi access, username, password and locale.\n\nConnect Raspberry to DHT22 sensor ([reference](https://github.com/FranzTscharf/Python-DHT22-Temperature-Humidity-Sensor-Raspberry-Pi)):\n\n![alt text](img/dht22_connection.png)\nGPIO pins:\n![alt text](img/raspberry_connector.png)\n\n\n### Install Tool\n\nOn the Raspberr Pi Zero W execute the following comands:\n```bash\ngit clone https://github.com/ptr33/temp_humidity_sensor.git\ncd temp_humidity_sensor/\npip install -r requirements.txt --break-system-packages\ngit update-index --assume-unchanged config.json\n```\n\nThen edit server settings, topics and hardware configuration in [config.json](https://github.com/ptr33/temp_humidity_sensor/blob/main/config.json)\n\nTo run the script use:\n```bash\n./getreading.py\n```\n\n### Crontab\n\nTo execute the script every 10 minutes, use crontab:\n```bash\ncrontab -e\n# add below lines to crontab, if you use nano, use ^O\u003cEnter\u003e^X to install\n# run every 10 minutes\n*/10 * * * * cd ~/temp_humidity_sensor/ \u0026\u0026 ./getreading.py\n```\n\n\n### Compile Adafruid_DHT binary (optional) \n\n```bash\ncd ~/temp_humidity_sensor/bcm2835_lib/bcm2835-1.75\n./configure\nmake\nsudo make install\ncd ../../Adafruit_DHT_Driver\nmake\nmake test\nmake clean\n```\nThe library was tested on a Raspbery Pi Zero W (first version) -\nif you want to use the driver on a different device, you might need to modify [LOW_HIGH_THRESHOLD](https://github.com/ptr33/temp_humidity_sensor/blob/dev/Adafruit_DHT_Driver/Adafruit_DHT.c#L31)\n\n\n#### Test\n\n```bash\ncd ~/temp_humidity_sensor/Adafruit_DHT_Driver\nsudo ./Adafruit_DHT 22 4\n```\nThe output should be:\n```\nptr@raspberrypi:~/temp_humidity_sensor/Adafruit_DHT_Driver $ sudo ./Adafruit_DHT 22 4\nUsing pin #4\nData (40): 0x2 0x17 0x0 0xe1 0xfa\nTemp =  22.5 *C, Hum = 53.5 %\n```\n\n\n## Integrate with Homeassistant\n\nCreate a MQTT client in [Homeassistant](https://www.home-assistant.io/) for the same MQTT server as used for publishing (configured config.json). Then edit the following files:\n\n*configuration.yaml*\n```yaml\nmqtt: !include mqtt.yaml\n```\n\n*mqtt.yaml*\n```yaml\nsensor:\n  - name: \"Temperature\"\n    state_topic: \"stat/room/temperature\"\n    state_class: measurement\n    unit_of_measurement: \"°C\"\n    device_class: temperature\n  - name: \"Humidity\"\n    state_topic: \"stat/room/humidity\"\n    state_class: measurement\n    unit_of_measurement: \"%\"\n    device_class: moisture\n  - name: \"Dewpoint\"\n    state_topic: \"stat/room/dewpoint\"\n    state_class: measurement\n    unit_of_measurement: \"°C\"\n    device_class: temperature\n```\n\nReload the configuration or restart homeassistant server for the new devices to appear.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptr33%2Ftemp_humidity_sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fptr33%2Ftemp_humidity_sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptr33%2Ftemp_humidity_sensor/lists"}