Overview
The aht20 node reads temperature and humidity from the ASAIR AHT20 sensor via I2C.
This affordable, factory-calibrated sensor provides good accuracy for its price point, making it ideal for
indoor air quality projects, smart home automation, and basic environmental monitoring.
Wiring (I2C)
Connection
VCC → 3.3V
GND → GND
SDA → GPIO 2 (Pin 3)
SCL → GPIO 3 (Pin 5)
Notes
Factory calibrated - no user calibration needed
Measurement takes ~80ms after trigger
Wait 20ms after power-on before first read
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| bus | number | 1 | I2C bus number |
| address | number | 0x38 | I2C address (fixed at 0x38) |
| interval | number | 5000 | Reading interval in milliseconds |
| tempUnit | string | "C" | Temperature unit: "C" or "F" |
Output
{
"payload": {
"temperature": 24.1,
"humidity": 48.5
},
"temperature": 24.1,
"humidity": 48.5,
"timestamp": 1640000000000
} Example: Indoor Air Quality Monitor
Calculate comfort index and display on a dashboard with historical trends.
// Function node: Comfort index calculation
var temp = msg.temperature;
var humidity = msg.humidity;
// Heat index calculation (simplified)
var heatIndex = temp;
if (temp >= 27 && humidity >= 40) {
heatIndex = -8.784 + 1.611 * temp + 2.338 * humidity
- 0.1461 * temp * humidity;
}
// Comfort level assessment
var comfort = "comfortable";
if (temp < 18) comfort = "too cold";
else if (temp > 26) comfort = "too warm";
else if (humidity < 30) comfort = "too dry";
else if (humidity > 60) comfort = "too humid";
msg.payload = {
temperature: temp,
humidity: humidity,
heatIndex: heatIndex.toFixed(1),
comfort: comfort,
score: comfort === "comfortable" ? 100 : 60
};
return msg; Example: Multi-Room Monitoring
Use multiple AHT20 sensors on separate I2C buses for room-by-room tracking.
// Since AHT20 has a fixed address, use I2C multiplexer
// or separate buses for multiple sensors
// Function node: Aggregate room data
var rooms = flow.get('roomData') || {};
var room = msg.topic; // e.g., "living_room", "bedroom"
rooms[room] = {
temperature: msg.temperature,
humidity: msg.humidity,
updated: Date.now()
};
flow.set('roomData', rooms);
// Find hottest and coldest rooms
var names = Object.keys(rooms);
var sorted = names.sort(function(a, b) {
return rooms[a].temperature - rooms[b].temperature;
});
msg.payload = {
rooms: rooms,
coldest: sorted[0],
warmest: sorted[sorted.length - 1]
};
return msg; Use Cases
Smart Home Climate
Room-by-room temperature and humidity dashboards
Indoor Air Quality
Pair with CO2 sensors for complete air quality monitoring
Server Room Monitoring
Alert when temperature or humidity exceed safe limits
Reptile Terrariums
Maintain proper temperature and humidity for pets