https://github.com/martinthoma/temperature-sensor
Build the perfect temperature/humidity sensor for my smart home
https://github.com/martinthoma/temperature-sensor
esp32 home-automation humidity humidity-sensor iot sensors smart-home temperature temperature-sensor
Last synced: 2 months ago
JSON representation
Build the perfect temperature/humidity sensor for my smart home
- Host: GitHub
- URL: https://github.com/martinthoma/temperature-sensor
- Owner: MartinThoma
- Created: 2025-07-20T18:09:59.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-21T16:40:08.000Z (11 months ago)
- Last Synced: 2025-12-26T21:58:16.302Z (6 months ago)
- Topics: esp32, home-automation, humidity, humidity-sensor, iot, sensors, smart-home, temperature, temperature-sensor
- Language: C
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Temperature- and Humidity Sensor
The idea behind this project is to create a temperature and humidity sensor that can be easily integrated into a home automation system, such as Home Assistant.
In a private house every room should have at
least one sensor, potentially more to get the
temperature gradient within a room (from floor
to ceiling, from window to door).
It is primarily designed to be used indoors.
As one home might have 15 rooms and every room might have 1-3 sensors, the price should be low
enough to allow for multiple sensors without breaking the bank.
For the same reason, the sensor should be low power, so it can run on batteries for a long time.
It also should not break the wi-fi by having too many sensors connected to the same network.
The sensor should cover:
* Temperature: -40°C to +60°C, so an unheated garage or an attic in summer can
be monitored
* Humidity: 0% to 100% RH, to account for all indoor environments
* Accuracy: ±1°C and ±5% RH, so it is not too expensive but still accurate
enough for most use cases
* One value every minute should always be enough
## Hardware
### Components: 9.63€
Component
Specs
Price
Price per piece
ESP-WROOM-32 Development board
two low-power Xtensa® 32-bit LX6, 520 KB of on-chip SRAM; Wi-Fi 802.11 b/g/n (802.11n up to 150 Mbps); Bluetooth v4.2 BR/EDR + BLE; –40 °C to +85 °C
7€
7€
DHT11 Temperature and Humidity Sensor
20-90%RH and 0-50 ℃; ±5%RH; ±2℃; Resolution of 1°C and 1% RH; Requires 3-5.5V DC
3x for 7.89€
2.63€
### Assembly
1. Connect the DHT11 sensor to the ESP32:
- VCC to 3.3V (3V3)
- GND to GND
- Data pin to GPIO 4 (D4)
## Software
### Size
```
$ idf.py size
Memory Type Usage Summary
┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Memory Type/Section ┃ Used [bytes] ┃ Used [%] ┃ Remain [bytes] ┃ Total [bytes] ┃
┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ Flash Code │ 567086 │ │ │ │
│ .text │ 567086 │ │ │ │
│ Flash Data │ 110564 │ │ │ │
│ .rodata │ 110308 │ │ │ │
│ .appdesc │ 256 │ │ │ │
│ IRAM │ 98143 │ 74.88 │ 32929 │ 131072 │
│ .text │ 97115 │ 74.09 │ │ │
│ .vectors │ 1028 │ 0.78 │ │ │
│ DRAM │ 33272 │ 18.41 │ 147464 │ 180736 │
│ .data │ 16672 │ 9.22 │ │ │
│ .bss │ 16600 │ 9.18 │ │ │
│ RTC FAST │ 36 │ 0.44 │ 8156 │ 8192 │
│ .force_fast │ 36 │ 0.44 │ │ │
│ RTC SLOW │ 24 │ 0.29 │ 8168 │ 8192 │
│ .rtc_slow_reserved │ 24 │ 0.29 │ │ │
└───────────────────────┴──────────────┴──────────┴────────────────┴───────────────┘
Total image size: 792501 bytes (.bin may be padded larger)
```
### Setup
1. Copy the environment variables template:
```bash
cp .envrc.example .envrc
```
2. Edit `.envrc` and set your WiFi credentials:
```bash
export WIFI_SSID="YourWiFiNetworkName"
export WIFI_PASS="YourWiFiPassword"
```
3. Source the environment variables before building:
```bash
source .envrc
```
### Development
Requirements:
```
. $HOME/esp/esp-idf/export.sh
```
Make sure to source your WiFi credentials and then build and flash:
```bash
source .envrc
idf.py -p /dev/ttyUSB0 flash monitor
```
## Communication
Home Assistant can get the data from the sensor via HTTP requests (polling a REST API).
### TODO
* Integrate into Home Assistant, maybe via [ESPHome](https://esphome.io/)
* [ESP32 Wi-Fi Provisioning via Bluetooth](https://randomnerdtutorials.com/esp32-wi-fi-provisioning-ble-arduino/)
* Make a rigid case, e.g. with a 3D printer. Should be easy to swap
batteries/plug in a USB cable.
* Run with batteries (2x AAA Battery Holder)
* Configure WiFi credentials via Bluetooth
* Use less energy:
- Switch from polling to MQTT
- Use deep sleep mode
- Switch from Wi-Fi to something
less power hungry (e.g. LoRaWAN, Zigbee, Thread, BLE, ESP-NOW)
## Improvements
* Sensor:
* The DHT22 (AM2302) would cover especially low temperatures (down to -40°C)
and has a better accuracy (±0.5% RH, ±0.3°C). It is almost twice as
expensive, though (~5€ per piece).
* The AHT20 is more accurate than the DHT22, has a higher resolution, requires a lower voltage, uses less power. [Wiring seems easy](https://www.espboards.dev/sensors/aht20/)
* The BME280 would also give Barometric Pressure. [Tutorial](https://randomnerdtutorials.com/esp32-bme280-arduino-ide-pressure-temperature-humidity/)
* The SHT35 has a slightly better accuracy than the AHT20, but is more expensive. The SHT45 additionally has lower power consumption, but is even more expensive.