Skip to content

Sensor Read Action ​

Action Type ​

ActionactionTypeDescription
ACTION_SENSOR_READ19Read 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 ​

SensorCategoryValueRead MethodOutput
SENSOR_ANALOG0ADC readRaw ADC value
SENSOR_DIGITAL1GPIO read0/1
SENSOR_DHT113DHT protocoltemperature, humidity
SENSOR_DHT224DHT protocoltemperature, humidity
SENSOR_DS18B205OneWiretemperature
SENSOR_ULTRASONIC6Trig+Echodistance_cm
SENSOR_CURRENT7ADC+calibrationcurrent_A
SENSOR_VOLTAGE8ADC+calibrationvoltage_V
SHT31driver registryI2Ctemperature, humidity
AHT20driver registryI2Ctemperature, humidity
BH1750driver registryI2Cilluminance
BMP280driver registryI2C, requires FASTBEE_ENABLE_I2C_SENSORStemperature, pressure, altitude
MPU6050driver registryI2C, requires FASTBEE_ENABLE_I2C_SENSORSaccelX/Y/Z, temperature, gyroX/Y/Z

Parameter Description ​

FieldDescription
targetPeriphIdTarget sensor peripheral ID
actionType19
actionValueJSON string describing periphId, sensorCategory, dataField and calibration/driver parameters
json
{
  "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:

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 ​

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:

  1. Edit the rule in the Peripheral Execution Management page

  2. Click the Add Action button

  3. Fill in the action configuration:

    FieldValueDescription
    Action TypeSelect Sensor ReadRead sensor
    Target PeripheralSelect dht1DHT11 peripheral ID
    Data Fieldtemperature or humidityField to read
    Display NameTemperature or HumidityName for reporting
    Unit°C or %Data unit
    Decimal Places1Keep 1 decimal place
  4. 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:

  1. Edit the rule, add an action

  2. Fill in:

    • Action Type: Select Sensor Read
    • Target Peripheral: Select ultrasonic1
    • Data Field: distance
    • Display Name: Distance
    • Unit: cm
    • Decimal Places: 1
  3. Click Save


Example 3: Read Current Sensor (with Calibration) ​

Scenario: Read ACS712 current sensor data

Configuration Steps:

  1. Edit the rule, add an action

  2. 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)
  3. 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:

json
[
  {"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 ​

json
{
  "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 ​

  1. Sampling Interval: Sensors have minimum sampling interval protection (DHT: 2000ms, Ultrasonic: 100ms, ADC: 200ms)
  2. Cache Mechanism: Repeated reads within the interval return cached values without actually triggering hardware reads
  3. Error Handling: Read failures do not interrupt execution of other actions in the rule
  4. Reporting Filter: Only SENSOR_READ and MODBUS_POLL results are precisely reported

FastBee | fastbee.cn