An ESP32 board costs less than a pizza, has Wi-Fi built in, and can read almost any cheap sensor. The hard part is not getting the data off the board. It is deciding what happens next: where the readings are stored, who gets alerted when something looks wrong, and how you notice when the device quietly goes offline. That is exactly the kind of glue work n8n is good at.
In this guide you will connect an ESP32 with a DHT22 temperature and humidity sensor to n8n using a Webhook node, then build workflows that log readings, send Telegram alerts, detect a dead sensor, and write a short AI summary every morning.
What you’ll build
- Sensor logger – every reading from the ESP32 is appended to a Google Sheet.
- Threshold alerts – Telegram message when temperature or humidity goes out of range, with a cooldown so you are not spammed.
- Offline watchdog – an alert when the device stops reporting.
- AI daily summary – an LLM reads yesterday’s data and sends a plain-language report.
You need an ESP32 dev board, a DHT22 (or DHT11) sensor, a 10kΩ pull-up resistor if your sensor is not on a breakout board, the Arduino IDE with the ESP32 board package, and an n8n instance reachable from your Wi-Fi network (n8n Cloud or self-hosted with a public HTTPS URL).
Step 1: Connect the ESP32 to n8n
There is no dedicated ESP32 node in n8n, and you do not need one. The board simply sends an HTTP POST with JSON, and the Webhook node receives it.
1.1 Create the webhook in n8n
- Create a new workflow and add a Webhook trigger node.
- Set HTTP Method to
POSTand set Path to something readable, for exampleesp32/readings. - Set Authentication to Header Auth and create a credential with Name
X-Device-Keyand a long random string as the Value. Requests without that header are rejected. - Leave Respond on Immediately so the board gets a fast reply and can go back to sleep or keep measuring.
- Copy the Test URL for now. You will switch to the Production URL once the workflow is published.
n8n gives every Webhook node two URLs. The test URL only listens while you click Listen for test event and shows the data in the editor. The production URL works once the workflow is published, and its runs appear under the Executions tab instead.
1.2 Wire the sensor
- DHT22 VCC → ESP32 3V3
- DHT22 DATA → GPIO 4 (with a 10kΩ resistor between DATA and VCC)
- DHT22 GND → ESP32 GND
1.3 Flash the sketch
In the Arduino IDE, install DHT sensor library and Adafruit Unified Sensor from the Library Manager. WiFi, HTTPClient and WiFiClientSecure ship with the ESP32 core.
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT22
const char* WIFI_SSID = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";
const char* WEBHOOK_URL = "https://your-n8n.example.com/webhook/esp32/readings";
const char* DEVICE_KEY = "your-long-random-key";
const char* DEVICE_ID = "garage-01";
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println(" connected");
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("DHT read failed");
delay(5000);
return;
}
if (WiFi.status() == WL_CONNECTED) {
WiFiClientSecure client;
client.setInsecure(); // testing only - use setCACert() in production
HTTPClient http;
http.begin(client, WEBHOOK_URL);
http.addHeader("Content-Type", "application/json");
http.addHeader("X-Device-Key", DEVICE_KEY);
String body = "{"device":"" + String(DEVICE_ID) +
"","temperature":" + String(t, 1) +
","humidity":" + String(h, 1) + "}";
int code = http.POST(body);
Serial.printf("POST %dn", code);
http.end();
}
delay(300000); // every 5 minutes
}
Click Listen for test event in n8n, then reset the board. You should see a payload where your values sit under body: {{ $json.body.temperature }}, {{ $json.body.humidity }} and {{ $json.body.device }}.
setInsecure() skips certificate validation, which is fine on a bench but not for a device you leave running. For production, load your server’s root CA with client.setCACert(), or keep the board on your LAN and post to a local n8n over HTTP.
Workflow 1: Log every reading to Google Sheets
Webhook (POST /esp32/readings)
↓
Edit Fields (Set)
↓
Google Sheets → Append Row
- Create a sheet with the columns
timestamp,device,temperature,humidity. - After the Webhook, add an Edit Fields (Set) node with:
timestamp={{ $now.setZone('Asia/Manila').toISO() }}device={{ $json.body.device }}temperature(Number) ={{ $json.body.temperature }}humidity(Number) ={{ $json.body.humidity }}
- Add a Google Sheets node, operation Append Row, pick your document and sheet, and set mapping to Map Automatically.
The timestamp comes from n8n, not the ESP32, so you do not have to set up NTP on the board. If you have not connected Google Sheets before, the n8n Google Sheets automation tutorial walks through the credential setup.
Workflow 2: Telegram alerts with a cooldown
Webhook
↓
IF (out of range?)
↓ true
Code (cooldown check)
↓
Telegram → Send Message
You can add this branch to the same workflow, running in parallel with the logger.
- Add an IF node with two conditions joined by OR:
- Number:
{{ $json.body.temperature }}is greater than32 - Number:
{{ $json.body.humidity }}is greater than80
- Number:
- On the true output, add a Code node so you only get one alert per 30 minutes:
const state = $getWorkflowStaticData('global'); const now = Date.now(); if (state.lastAlert && now - state.lastAlert < 30 * 60 * 1000) { return []; } state.lastAlert = now; return $input.all(); - Add a Telegram node, resource Message, operation Send Message, with your chat ID and text:
⚠️ {{ $('Webhook').item.json.body.device }} Temp: {{ $('Webhook').item.json.body.temperature }} °C Humidity: {{ $('Webhook').item.json.body.humidity }} %
Workflow static data is only saved for production executions, so the cooldown only kicks in once the workflow is published. Need a bot token and chat ID? See the n8n Telegram bot tutorial.
Workflow 3: Offline watchdog
A sensor that stops reporting is often worse than one reporting a high value, because nothing tells you. This separate workflow checks the sheet on a schedule.
Schedule Trigger (every 15 min)
↓
Google Sheets → Get Row(s)
↓
Code (minutes since last reading)
↓
IF (> 20 minutes)
↓ true
Telegram → Send Message
- Add a Schedule Trigger set to every 15 minutes.
- Add Google Sheets with operation Get Row(s) on the same sheet.
- Add a Code node to keep only the latest row and compute its age:
const rows = $input.all(); const last = rows[rows.length - 1].json; const ageMin = (Date.now() - new Date(last.timestamp).getTime()) / 60000; return [{ json: { device: last.device, lastSeen: last.timestamp, ageMin: Math.round(ageMin) } }]; - Add an IF node:
{{ $json.ageMin }}is greater than20. - On true, send a Telegram message:
{{ $json.device }} has been silent for {{ $json.ageMin }} minutes. Check power and Wi-Fi.
With the sketch posting every 5 minutes, 20 minutes means several missed readings in a row, which filters out a single dropped request.
Workflow 4: AI daily summary
Schedule Trigger (daily 7:00 AM)
↓
Google Sheets → Get Row(s)
↓
Code (filter last 24h + stats)
↓
OpenAI → Message a Model
↓
Telegram → Send Message
- Add a Schedule Trigger at 7:00 AM (check that the workflow timezone in settings is yours).
- Fetch rows with Google Sheets → Get Row(s).
- In a Code node, keep the last 24 hours and compute min, max and average:
const since = Date.now() - 24 * 60 * 60 * 1000; const rows = $input.all().map(i => i.json) .filter(r => new Date(r.timestamp).getTime() >= since); const t = rows.map(r => Number(r.temperature)); const h = rows.map(r => Number(r.humidity)); const avg = a => (a.reduce((x, y) => x + y, 0) / a.length).toFixed(1); return [{ json: { count: rows.length, tMin: Math.min(...t), tMax: Math.max(...t), tAvg: avg(t), hMin: Math.min(...h), hMax: Math.max(...h), hAvg: avg(h) } }]; - Add the OpenAI node (resource Text, operation Message a Model) or any chat model you prefer, with a prompt like:
You are a home monitoring assistant. Summarize these sensor stats for the last 24 hours in 3 short sentences. Mention anything unusual and one practical suggestion. Readings: {{ $json.count }} Temperature min/avg/max: {{ $json.tMin }} / {{ $json.tAvg }} / {{ $json.tMax }} °C Humidity min/avg/max: {{ $json.hMin }} / {{ $json.hAvg }} / {{ $json.hMax }} % - Send the model’s reply to Telegram. Check the OpenAI node’s output panel for the exact field path of the response text and reference it in the message.
Computing the numbers in code and only asking the model to explain them keeps the summary accurate and the token cost tiny, since you send a few numbers instead of hundreds of rows.
Troubleshooting
- HTTP code -1 on the ESP32: the board could not connect. Check the URL, that n8n is reachable from your network, and that you used
WiFiClientSecurefor anhttps://URL. - 404 from n8n: you are calling the test URL without listening, or the production URL on an unpublished workflow.
- 403 / authorization errors: the
X-Device-Keyheader name or value does not match the Header Auth credential exactly. - “DHT read failed”: check wiring and the pull-up resistor, and do not read the DHT22 more often than every 2 seconds.
- Values arrive as text: make sure the Edit Fields types are set to Number, otherwise IF comparisons may misbehave.
- Cooldown never resets during testing: static data is not saved for manual test runs; publish the workflow to test it properly.
Wrapping up
With one Webhook node and a few lines of Arduino code, an ESP32 becomes a proper data source for n8n: readings are logged, alerts are rate-limited, a silent device gets noticed, and an AI model turns raw numbers into a morning briefing. From here you can swap the DHT22 for a soil moisture, gas or current sensor and reuse the same workflows almost unchanged.
Want to see hardware and automation builds like this in action? Watch the videos on Node & Volt on YouTube.


