SHT31 Temperature and Humidity Sensor
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
| SHT31 | ESP32 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | GPIO21 |
| SCL | GPIO22 |
Default address is 0x44; some modules can be switched to 0x45.
Configuration
Method 1: Web Interface Configuration (Recommended)
Before saving SHT31 configuration, verify the I2C address, sampling interval, and temperature/humidity fields.
Step 1: Navigate to Peripheral Management Page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add SHT31 Peripheral
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID sht31_i2cUnique identifier Name SHT31 Temp & HumidityDisplay name Peripheral Type Generic Sensor (type: 38) I2C sensor SDA Pin 21I2C data pin SCL Pin 22I2C clock pin I2C Address 0x440x44 or 0x45 Sampling Interval 50005 seconds Click Save
Step 3: Verify Configuration
- Find the newly added peripheral in the peripheral list
- Click the Enable toggle
- 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
{
"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
- Switch to the Peripheral Execution Management tab
- Click the Add Rule button
- Configure a timer trigger:
- Trigger Type: Timer Trigger
- Execution Interval: 30 seconds
- Add action:
- Action 1: Read temperature
- Action Type: Sensor Read
- Target Peripheral: sht31_i2c
- Data Field: temperature
- Action 1: Read temperature
- Enable Report Data After Execution
- Click Save
Create High Temperature Relay Rule
- Create a new rule
- Configure an event trigger:
- Trigger Type: Event Trigger
- Event ID: ds:sht31_i2c_temperature
- Comparison: Greater Than
- Comparison Value: 35 (℃)
- Add action:
- Action Type: High Level
- Target Peripheral: relay_01 (fan relay)
- Click Save
💡 Tip: SHT31 is suitable for precision temperature control and constant humidity scenarios
JSON Configuration Example
{
"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
{
"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
| dataField | Meaning | Unit |
|---|---|---|
temperature | Temperature | ℃ |
humidity | Relative Humidity | % |
