Sensor Read Action
Sensor Read Action
Action Type
| Action | actionType | Description |
|---|---|---|
| ACTION_SENSOR_READ | 19 | Read sensor data |
Overview
The sensor read action triggers a specified sensor peripheral to perform one data collection. The collection result is stored in the sensor cache and reported via MQTT when the rule has reportAfterExec: true.
When reading this page, you can break down a single read into three segments according to the diagram: the target peripheral driver is responsible for getting the raw value, the sensor cache is responsible for forming the id.field data source, and the peripheral execution rule is responsible for deciding whether to report, display, or trigger subsequent actions.
Supported Sensor Types
| SensorCategory | Value | Read Method | Output |
|---|---|---|---|
| SENSOR_ANALOG | 0 | ADC read | Raw ADC value |
| SENSOR_DIGITAL | 1 | GPIO read | 0/1 |
| SENSOR_DHT11 | 3 | DHT protocol | temperature, humidity |
| SENSOR_DHT22 | 4 | DHT protocol | temperature, humidity |
| SENSOR_DS18B20 | 5 | OneWire | temperature |
| SENSOR_ULTRASONIC | 6 | Trig+Echo | distance_cm |
| SENSOR_CURRENT | 7 | ADC+calibration | current_A |
| SENSOR_VOLTAGE | 8 | ADC+calibration | voltage_V |
| SHT31 | driver registry | I2C | temperature, humidity |
| AHT20 | driver registry | I2C | temperature, humidity |
| BH1750 | driver registry | I2C | illuminance |
| BMP280 | driver registry | I2C, requires FASTBEE_ENABLE_I2C_SENSORS | temperature, pressure, altitude |
| MPU6050 | driver registry | I2C, requires FASTBEE_ENABLE_I2C_SENSORS | accelX/Y/Z, temperature, gyroX/Y/Z |
Parameter Description
| Field | Description |
|---|---|
| targetPeriphId | Target sensor peripheral ID |
| actionType | 19 |
| actionValue | JSON string describing periphId, sensorCategory, dataField and calibration/driver parameters |
Recommended actionValue Format
{
"periphId": "sht31_i2c",
"sensorCategory": "SHT31",
"dataField": "temperature",
"sensorLabel": "Temperature",
"unit": "°C",
"decimalPlaces": 1,
"driverParams": {
"addr": "0x44",
"sda": 21,
"scl": 22
}
}ADC current/voltage sensors can add calibration parameters in the same JSON:
{
"periphId": "current_01",
"sensorCategory": "current",
"dataField": "current",
"sensorLabel": "Current",
"unit": "A",
"decimalPlaces": 3,
"sensitivity": 0.100,
"zeroOffset": 1.65,
"vRef": 3.3,
"adcMax": 4095
}Configuration Examples
Method 1: Web Interface Configuration (Recommended)
The peripheral execution page is shown below. When configuring sensor actions, verify the peripheral ID, sensor category, data field, and sampling interval in actionValue.
Example 1: Read DHT11 Temperature and Humidity
Scenario: Read temperature and humidity data from DHT11 sensor
Configuration Steps:
Edit the rule in the Peripheral Execution Management page
Click the Add Action button
Fill in the action configuration:
Field Value Description Action Type Select Sensor Read Read sensor Target Peripheral Select dht1DHT11 peripheral ID Data Field temperatureorhumidityField to read Display Name TemperatureorHumidityName for reporting Unit °Cor%Data unit Decimal Places 1Keep 1 decimal place Click the Save button
💡 Tip: DHT11 reads both temperature and humidity fields simultaneously
Example 2: Read Ultrasonic Distance
Scenario: Read distance data from HC-SR04 ultrasonic sensor
Configuration Steps:
Edit the rule, add an action
Fill in:
- Action Type: Select Sensor Read
- Target Peripheral: Select
ultrasonic1 - Data Field:
distance - Display Name:
Distance - Unit:
cm - Decimal Places:
1
Click Save
Example 3: Read Current Sensor (with Calibration)
Scenario: Read ACS712 current sensor data
Configuration Steps:
Edit the rule, add an action
Fill in:
- Action Type: Select Sensor Read
- Target Peripheral: Select
current_sensor - Data Field:
current - Display Name:
Current - Unit:
A - Decimal Places:
3 - Sensitivity:
0.100(fill based on module) - Zero Offset:
1.65(VCC/2) - Reference Voltage:
3.3 - ADC Max:
4095(ESP32 is 12-bit)
Click Save
💡 Tip: Current/voltage sensors require calibration parameters for accurate conversion
Method 2: JSON Configuration File Import
Data Reporting Format
Sensor read results reported via MQTT format:
[
{"id": "dht1.temperature", "value": "25.6"},
{"id": "dht1.humidity", "value": "65.2"}
]Sensor Cache
Read data is automatically stored in the sensor cache (SensorReadCache), which can be referenced by OLED display template ${id.field}.
Complete Rule Example
Timed Collection and Reporting
{
"id": "exec_sensor_poll",
"name": "Timed Sensor Collection",
"enabled": false,
"execMode": 0,
"triggers": [
{
"triggerType": 1,
"triggerPeriphId": "",
"operatorType": 0,
"compareValue": "",
"timerMode": 0,
"intervalSec": 60,
"timePoint": "",
"eventId": "",
"pollResponseTimeout": 1000,
"pollMaxRetries": 2,
"pollInterPollDelay": 100
}
],
"actions": [
{
"targetPeriphId": "dht1",
"actionType": 19,
"actionValue": "",
"useReceivedValue": false,
"syncDelayMs": 0,
"execMode": 0
},
{
"targetPeriphId": "ultrasonic1",
"actionType": 19,
"actionValue": "",
"useReceivedValue": false,
"syncDelayMs": 200,
"execMode": 0
}
],
"protocolType": 0,
"scriptContent": "",
"reportAfterExec": true
}Precautions
- Sampling Interval: Sensors have minimum sampling interval protection (DHT: 2000ms, Ultrasonic: 100ms, ADC: 200ms)
- Cache Mechanism: Repeated reads within the interval return cached values without actually triggering hardware reads
- Error Handling: Read failures do not interrupt execution of other actions in the rule
- Reporting Filter: Only SENSOR_READ and MODBUS_POLL results are precisely reported
