Hi everyone🤗!
I’m excited to share my latest project with you: a DIY temperature and humidity meter that I built using the XIAO ESP32C6, the XIAO expansion board, and the SHT31 temperature and humidity sensor. My goal was to create a device that could help me monitor the humidity levels in my home, especially as I live in a coastal tropical area where humidity can fluctuate greatly.
The idea came from my need to maintain a comfortable indoor environment. Sometimes the air can be too humid, while other times, it can get quite dry😵💫.
I wanted a way to stay informed about the humidity levels in my rooms. Since the XIAO ESP32C6 has low power consumption, I decided to integrate it with HomeAssistant using the Zigbee protocol. This allows me to easily display the temperature and humidity data while receiving alerts about when to dehumidify or humidify my living space.
What I Used● XIAO ESP32C6: This little guy is the heart of the project, handling both Wi-Fi and Zigbee connections while being low power, which helps extend battery life and makes it perfect for continuous monitoring.
● Grove SHT31 Sensor: It gives accurate and up-to-date temp and humidity readings.
● XIAO Expansion Board: Made it easier to connect everything together.
● 3D Printed Shell: I designed a custom enclosure to hold all the parts and make it look nice! And It’s super compact too, measuring just 60x30x30mm, making it an elegant and tidy addition to any room.
○ Top Cover: Features the Seeed Studio logo.
○ Bottom Cover: Has slots to expose the temperature and humidity sensor, along with screw holes for mounting.
○ Middle Connector: This part securely connects and holds the expansion board and sensor module in place.
Before using it to connect to HomeAssistant, please confirm if your HomeAssistant is equipped with peripherals that receive Zigbee signals, such as: Home Assistant Connect ZBT-1.
So, here's what this small device looks like😎:
Here are the effect screenshots of the HomeAssistant interface:
1. Real-Time Monitoring: Once the device is powered on, the temperature and humidity data refreshes in real-time on the HomeAssistant interface. You can see the fluctuating readings as the environment changes!
2. Graphical Representation: The monitoring data can be visualized using graphs in HomeAssistant, making it easy to track changes over time. The chart below shows temperature and humidity fluctuations over the past few hours.
Here’s the code I used for the project. This code is modified from the Zigbee example in Arduino-ESP32:
#ifndef ZIGBEE_MODE_ED
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
#endif
#include "Zigbee.h"
#include <Wire.h>
#include "SHT31.h"
/* Zigbee temperature sensor configuration */
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
uint8_t button = BOOT_PIN;
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
SHT31 sht31 = SHT31();
/************************ Temp sensor *****************************/
static void temp_sensor_value_update(void *arg) {
float humi, temp;
for (;;) {
// Read temperature&humidity sensor value
temp = sht31.getTemperature();
humi = sht31.getHumidity();
Serial.printf("humidity: %.2f %% temprature: %.2f°C\r\n", humi, temp);
// Update temperature and humidity values in Temperature sensor EP
zbTempSensor.setTemperature(temp);
zbTempSensor.setHumidity(humi);
// Report temperature and humidity values
zbTempSensor.report();
delay(1000);
}
}
/********************* Arduino functions **************************/
void setup() {
Serial.begin(115200);
// Init RF
pinMode(WIFI_ENABLE, OUTPUT);
digitalWrite(WIFI_ENABLE, LOW); // Activate RF switch control
delay(100);
pinMode(WIFI_ANT_CONFIG, OUTPUT);
digitalWrite(WIFI_ANT_CONFIG, LOW); // Use built-in antenna
// Init button switch
pinMode(button, INPUT_PULLUP);
// Init Sensor
sht31.begin();
// Optional: set Zigbee device name and model
zbTempSensor.setManufacturerAndModel("Espressif", "ZigbeeTempSensor");
// Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
zbTempSensor.setMinMaxValue(10, 50);
// Optional: Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
zbTempSensor.setTolerance(1);
// Add humidity cluster to the temperature sensor device with min, max and tolerance values
zbTempSensor.addHumiditySensor(0, 100, 1);
// Add endpoint to Zigbee Core
Zigbee.addEndpoint(&zbTempSensor);
Serial.println("Starting Zigbee...");
// When all EPs are registered, start Zigbee in End Device mode
if (!Zigbee.begin()) {
Serial.println("Zigbee failed to start!");
Serial.println("Rebooting...");
ESP.restart();
} else {
Serial.println("Zigbee started successfully!");
}
Serial.println("Connecting to network");
while (!Zigbee.connected()) {
Serial.print(".");
delay(100);
}
Serial.println();
// Start Temperature sensor reading task
xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 2048, NULL, 10, NULL);
// Set reporting interval for temperature measurement in seconds, must be called after Zigbee.begin()
// min_interval and max_interval in seconds, delta (temp change in 0,1 °C)
// if min = 1 and max = 0, reporting is sent only when temperature changes by delta
// if min = 0 and max = 10, reporting is sent every 10 seconds or temperature changes by delta
// if min = 0, max = 10 and delta = 0, reporting is sent every 10 seconds regardless of temperature change
zbTempSensor.setReporting(1, 0, 1);
}
void loop() {
// Checking button for factory reset
if (digitalRead(button) == LOW) { // Push button pressed
// Key debounce handling
delay(100);
int startTime = millis();
while (digitalRead(button) == LOW) {
delay(50);
if ((millis() - startTime) > 3000) {
// If key pressed for more than 3secs, factory reset Zigbee and reboot
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
delay(1000);
Zigbee.factoryReset();
}
}
zbTempSensor.report();
}
delay(100);
}
After programming XIAO ESP32C6 and successfully connecting it to HomeAssistant, you can also view the current temperature and humidity values through the serial port:
I’m thinking of adding some cool features like:
● A small display to show readings right on the device🖥️.
● More sensors, like for air quality, to keep an eye on everything👀.
● Better notifications, maybe even for my phone✨!
Let Me Know What You Think!Do you like this project? I’d love to hear your thoughts or any suggestions you might have. Have any of you done similar projects? Share your tips🙋!
Comments
Please log in or sign up to comment.