Skip to content

AHT20 Temperature and Humidity Sensor ​

The AHT20 is a low-cost I2C temperature and humidity sensor, suitable as a more stable replacement for DHT11/DHT22 for indoor environment monitoring. The current driver is a lightweight implementation that does not depend on additional third-party libraries, making it available for slim ESP32 firmware.

Wiring ​

AHT20ESP32
VCC3.3V
GNDGND
SDAGPIO21
SCLGPIO22

Default address is 0x38.

Configuration ​

Before saving AHT20 configuration, verify the I2C bus, address, and sampling interval.

Step 1: Navigate to Peripheral Management Page ​

  1. Open a browser and navigate to the ESP32 IP address
  2. After logging in, click Peripheral Configuration in the left menu

Step 2: Add AHT20 Peripheral ​

  1. Click the Add Peripheral button

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDaht20_i2cUnique identifier
    NameAHT20 Temp & HumidityDisplay name
    Peripheral TypeGeneric Sensor (type: 38)I2C sensor
    SDA Pin21I2C data pin
    SCL Pin22I2C clock pin
    I2C Address0x38Default address
    Sampling Interval50005 seconds
  3. Click Save

Step 3: Verify Configuration ​

  1. Find the newly added peripheral in the peripheral list
  2. Click the Enable toggle
  3. Wait 5 seconds and check temperature and humidity data

💡 Tip: AHT20 is a low-cost I2C alternative to DHT11/DHT22 with better accuracy


Method 2: JSON Configuration File Import ​

json
{
  "id": "aht20_i2c",
  "name": "AHT20 Temp & Humidity",
  "type": 2,
  "enabled": false,
  "pinCount": 2,
  "pins": [21, 22, 255, 255, 255, 255, 255, 255],
  "params": {
    "frequency": 100000,
    "address": 0,
    "isMaster": true
  }
}

Peripheral Execution Integration ​

Web Interface Configuration Steps ​

Create Humidity Collection and Control Rule

  1. Click Peripheral Execution in the left menu
  2. Click the Add Rule button
  3. Configure a timer trigger:
    • Trigger Type: Timer Trigger
    • Execution Interval: 30 seconds
  4. Add action:
    • Action 1: Read humidity
      • Action Type: Sensor Read
      • Target Peripheral: aht20_i2c
      • Data Field: humidity
  5. Enable Report Data After Execution
  6. Click Save

Create Low Humidity Humidifier Rule

  1. Create a new rule
  2. Configure an event trigger:
    • Trigger Type: Event Trigger
    • Event ID: ds:aht20_i2c_humidity
    • Comparison: Less Than
    • Comparison Value: 40 (%)
  3. Add action:
    • Action Type: High Level
    • Target Peripheral: relay_humidifier (humidifier relay)
  4. Click Save

💡 Tip: Event ID format is ds:{peripheralID}_{fieldName}


JSON Configuration Example ​

json
{
  "id": "exec_aht20_humidity_read",
  "name": "AHT20 Humidity Collection",
  "enabled": false,
  "triggers": [
    {
      "triggerType": 1,
      "timerMode": 0,
      "intervalSec": 30
    }
  ],
  "actions": [
    {
      "targetPeriphId": "aht20_i2c",
      "actionType": 19,
      "actionValue": "{\"periphId\":\"aht20_i2c\",\"sensorCategory\":\"AHT20\",\"dataField\":\"humidity\",\"sensorLabel\":\"Humidity\",\"unit\":\"%\",\"decimalPlaces\":1,\"driverParams\":{\"addr\":\"0x38\",\"sda\":21,\"scl\":22}}",
      "useReceivedValue": false,
      "syncDelayMs": 0,
      "execMode": 0
    }
  ],
  "reportAfterExec": true
}

Low Humidity Humidifier Relay ​

json
{
  "id": "exec_aht20_dry_relay",
  "name": "AHT20 Low Humidity Humidifier",
  "enabled": false,
  "triggers": [
    {
      "triggerType": 4,
      "eventId": "ds:aht20_i2c_humidity",
      "operatorType": 3,
      "compareValue": "40"
    }
  ],
  "actions": [
    {
      "targetPeriphId": "relay_humidifier",
      "actionType": 0,
      "actionValue": "",
      "useReceivedValue": false,
      "syncDelayMs": 0,
      "execMode": 0
    }
  ],
  "reportAfterExec": true
}

Available Data Fields ​

dataFieldMeaningUnit
temperatureTemperature℃
humidityRelative Humidity%

FastBee | fastbee.cn