Four ESP32 projects can add features to a home for less than $10 each: measuring temperature, detecting ambient light, or alerting you if the refrigerator gets warm. XDA describes builds using AHT10, BH1750, and DS18B20 sensors.
The examples below show independent implementations of those ideas, not the author's original code. To make them practical, the first two send events to Home Assistant webhooks, the third transmits lux readings to a PC, and the fourth publishes alerts to ntfy. You will need to adapt credentials, pins, and thresholds to your setup.
Preparation: board, sensors, and services
Install ESP32 support in Arduino IDE and add the Adafruit AHTX0, BH1750, OneWire, and DallasTemperature libraries through the library manager. The examples use Wi-Fi and serial output to check readings. For the Home Assistant builds, create two webhook-triggered automations—one to turn on and one to turn off—and copy their IDs into the sketch.
XDA's thermostat reuses a Tapo plug that's already connected to Home Assistant; the temperature reading does not directly control mains power. Leave switching to the plug and add safeguards to prevent rapid cycling. The article mentions a minimum five-minute wait after switching off, a maximum of four hours switched on, a 30-minute lockout, and a safe shutdown at startup.
1. Thermostat with AHT10 and Home Assistant
The AHT10 measures the temperature; the ESP32 uses a simple hysteresis band to avoid turning the system on and off around a single value. This sketch sends a webhook when the state changes. Configure the thresholds and off-time according to your equipment; the values in the code are example parameters, not settings recommended by XDA.
#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_AHTX0.h>
const char* ssid = "TU_WIFI";
const char* password = "TU_CLAVE";
const char* haBase = "http://homeassistant.local:8123/api/webhook/";
const char* onHook = "ID_WEBHOOK_ENCENDER";
const char* offHook = "ID_WEBHOOK_APAGAR";
Adafruit_AHTX0 aht;
const float encenderSobre = 27.0;
const float apagarBajo = 25.0;
const unsigned long esperaApagado = 5UL * 60UL * 1000UL;
const unsigned long maximoEncendido = 4UL * 60UL * 60UL * 1000UL;
bool activo = false;
unsigned long cambioEstado = 0;
void webhook(const char* id) {
HTTPClient http;
http.begin(String(haBase) + id);
http.GET();
http.end();
}
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
if (!aht.begin()) while (true) delay(1000);
webhook(offHook); // Apagado seguro al arrancar
cambioEstado = millis();
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
unsigned long ahora = millis();
Serial.printf("Temperatura: %.1f C\n", temp.temperature);
if (!activo && temp.temperature >= encenderSobre &&
ahora - cambioEstado >= esperaApagado) {
webhook(onHook);
activo = true;
cambioEstado = ahora;
}
if (activo && (temp.temperature <= apagarBajo ||
ahora - cambioEstado >= maximoEncendido)) {
webhook(offHook);
activo = false;
cambioEstado = ahora;
}
delay(5000);
}
The author also imposes a 30-minute lockout after the maximum on-time. This example does not include it: to reproduce that policy, add a separate lockout state and prevent the equipment from restarting until it expires. Do not connect loads directly to the board's pins.
2. Ambient light to control a bulb
The BH1750 reports illuminance in lux. XDA places the sensor next to a window and calibrates the room in darkness and with the bulb at 50% to set the limits. The following snippet implements switching on and off using webhooks; replace the illustrative thresholds with a calibration for your room.
#include <WiFi.h>
#include <HTTPClient.h>
#include <BH1750.h>
#include <Wire.h>
const char* ssid = "TU_WIFI";
const char* password = "TU_CLAVE";
const char* haBase = "http://homeassistant.local:8123/api/webhook/";
const char* onHook = "ID_WEBHOOK_LUZ_ON";
const char* offHook = "ID_WEBHOOK_LUZ_OFF";
BH1750 lightMeter;
bool luzEncendida = false;
const float umbralEncender = 80.0;
const float umbralApagar = 250.0;
void webhook(const char* id) {
HTTPClient http;
http.begin(String(haBase) + id);
http.GET();
http.end();
}
void setup() {
Serial.begin(115200);
Wire.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
if (!lightMeter.begin()) while (true) delay(1000);
}
void loop() {
float lux = lightMeter.readLightLevel();
Serial.printf("Luz: %.1f lux\n", lux);
if (!luzEncendida && lux < umbralEncender) {
webhook(onHook);
luzEncendida = true;
} else if (luzEncendida && lux > umbralApagar) {
webhook(offHook);
luzEncendida = false;
}
delay(5000);
} The original automation makes Home Assistant ignore turn-on requests while the user is asleep. That condition must be configured in Home Assistant: the sketch does not know your schedule. According to XDA, this build is better suited to a room that receives direct sunlight.
3. Adjust monitor brightness from the PC
The third idea also uses the BH1750, but the ESP32 reports lux readings to the computer over USB serial. XDA explains that the PC can adjust the monitor through DDC/CI, a control method that uses the I2C channel available in HDMI or DisplayPort cables. The author needed a background Python process and found that some monitors were incompatible or used different scales.
This PC example requires the ddcutil command-line tool to be installed and the monitor to support DDC/CI. The display number may vary; check it first. The ESP32 sends one reading per line, and the program limits the calculated brightness to the range reported by the monitor.
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup() {
Serial.begin(115200);
Wire.begin();
lightMeter.begin();
}
void loop() {
float lux = lightMeter.readLightLevel();
if (lux >= 0) Serial.println(lux, 1);
delay(2000);
}
import serial
import subprocess
# Cambia el puerto por el que corresponda a tu ESP32.
port = serial.Serial("/dev/ttyUSB0", 115200, timeout=2)
monitor = "1"
for raw in port:
try:
lux = float(raw.decode("utf-8").strip())
except (ValueError, UnicodeDecodeError):
continue
# Mapea 0-500 lux al rango 0-100 de brillo.
brightness = round(max(0, min(100, lux / 5)))
subprocess.run(
["ddcutil", "--display", monitor, "setvcp", "10", str(brightness)],
check=False,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
The linear mapping is just a starting point for testing: XDA describes a response that raises brightness to 100% when the room lights are at full power, but does not publish a universal curve. A monitor may not respond or may use a different scale; test each display separately.
4. Refrigerator temperature alert
The probe mentioned has a long cable that can pass through the door seal, and the circuit uses a 4.7 kΩ resistor. The following firmware waits for ten minutes of readings above the limit before publishing to an ntfy server.
#include <WiFi.h>
#include <HTTPClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const char* ssid = "TU_WIFI";
const char* password = "TU_CLAVE";
const char* ntfyUrl = "https://ntfy.example/TU_TEMA";
const int pinSonda = 4;
const float limiteC = 8.0;
OneWire oneWire(pinSonda);
DallasTemperature sensor(&oneWire);
unsigned long desdeCalor = 0;
unsigned long ultimoAviso = 0;
const unsigned long diezMinutos = 10UL * 60UL * 1000UL;
const unsigned long treintaMinutos = 30UL * 60UL * 1000UL;
void avisar(float temperatura) {
HTTPClient http;
http.begin(ntfyUrl);
http.addHeader("Content-Type", "text/plain; charset=utf-8");
String mensaje = "Nevera caliente: " + String(temperatura, 1) + " C";
http.POST(mensaje);
http.end();
}
void setup() {
Serial.begin(115200);
sensor.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
}
void loop() {
sensor.requestTemperatures();
float c = sensor.getTempCByIndex(0);
unsigned long ahora = millis();
Serial.printf("Nevera: %.1f C\n", c);
if (c > limiteC) {
if (desdeCalor == 0) desdeCalor = ahora;
if (ahora - desdeCalor >= diezMinutos &&
(ultimoAviso == 0 || ahora - ultimoAviso >= treintaMinutos)) {
avisar(c);
ultimoAviso = ahora;
}
} else {
desdeCalor = 0;
ultimoAviso = 0;
}
delay(30000);
}
The author takes a reading every 30 seconds, alerts after ten minutes of elevated temperature, and repeats the alert every thirty minutes while the problem persists. Adjust this sketch's threshold to its intended use. Protect the ntfy endpoint if you do not want anyone who knows it to publish to your topic.
Issues worth anticipating
A poorly positioned light sensor may measure the bulb rather than the room's brightness; that's why XDA's build places it facing the window. In the thermostat, an automation that reacts to every reading without hysteresis may oscillate near the threshold. And if Home Assistant or Wi-Fi is unavailable, the temperature and light projects can no longer perform their remote functions.
Monitor adjustment depends on DDC/CI compatibility, while the refrigerator alarm needs Wi-Fi and an accessible ntfy server. XDA says the thermostat and monitor adjustment are still in use, and describes all four builds as DIY projects, not finished products. A useful first step is to test each sensor over serial before enabling automations.