Skip to content

SHT31 Temperature and Humidity Sensor ​

The SHT31 is a commonly used I2C temperature and humidity sensor with better accuracy and stability than the DHT11, suitable for environmental monitoring, temperature control, and constant humidity scenarios. The current driver is a lightweight implementation that does not depend on additional third-party libraries, and is available for esp32, esp32c3, esp32s3, and esp32s3-F16R8.

Wiring ​

SHT31ESP32
VCC3.3V
GNDGND
SDAGPIO21
SCLGPIO22

Default address is 0x44; some modules can be switched to 0x45.

Configuration ​

Before saving SHT31 configuration, verify the I2C address, sampling interval, and temperature/humidity fields.

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 SHT31 Peripheral ​

  1. Click the Add Peripheral button

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDsht31_i2cUnique identifier
    NameSHT31 Temp & HumidityDisplay name
    Peripheral TypeGeneric Sensor (type: 38)I2C sensor
    SDA Pin21I2C data pin
    SCL Pin22I2C clock pin
    I2C Address0x440x44 or 0x45
    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: SHT31 has better accuracy and stability than DHT11, supported by all ESP32 variants


Method 2: JSON Configuration File Import ​

json
{
  "id": "sht31_i2c",
  "name": "SHT31 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 Temperature 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 temperature
      • Action Type: Sensor Read
      • Target Peripheral: sht31_i2c
      • Data Field: temperature
  5. Enable Report Data After Execution
  6. Click Save

Create High Temperature Relay Rule

  1. Create a new rule
  2. Configure an event trigger:
    • Trigger Type: Event Trigger
    • Event ID: ds:sht31_i2c_temperature
    • Comparison: Greater Than
    • Comparison Value: 35 (℃)
  3. Add action:
    • Action Type: High Level
    • Target Peripheral: relay_01 (fan relay)
  4. Click Save

💡 Tip: SHT31 is suitable for precision temperature control and constant humidity scenarios


JSON Configuration Example ​

json
{
  "id": "exec_sht31_temperature_read",
  "name": "SHT31 Temperature Collection",
  "enabled": false,
  "triggers": [
    {
      "triggerType": 1,
      "timerMode": 0,
      "intervalSec": 30
    }
  ],
  "actions": [
    {
      "targetPeriphId": "sht31_i2c",
      "actionType": 19,
      "actionValue": "{\"periphId\":\"sht31_i2c\",\"sensorCategory\":\"SHT31\",\"dataField\":\"temperature\",\"sensorLabel\":\"Temperature\",\"unit\":\"℃\",\"decimalPlaces\":1,\"driverParams\":{\"addr\":\"0x44\",\"sda\":21,\"scl\":22}}",
      "useReceivedValue": false,
      "syncDelayMs": 0,
      "execMode": 0
    }
  ],
  "reportAfterExec": true
}

High Temperature Relay ​

json
{
  "id": "exec_sht31_hot_relay",
  "name": "SHT31 High Temperature Relay",
  "enabled": false,
  "triggers": [
    {
      "triggerType": 4,
      "eventId": "ds:sht31_i2c_temperature",
      "operatorType": 2,
      "compareValue": "35"
    }
  ],
  "actions": [
    {
      "targetPeriphId": "relay_01",
      "actionType": 0,
      "actionValue": "",
      "useReceivedValue": false,
      "syncDelayMs": 0,
      "execMode": 0
    }
  ],
  "reportAfterExec": true
}

Available Data Fields ​

dataFieldMeaningUnit
temperatureTemperature℃
humidityRelative Humidity%

FastBee | fastbee.cn