Skip to content

Platform Trigger (PLATFORM_TRIGGER) ​

Overview ​

Platform trigger (triggerType = 0) is used to respond to data commands delivered by the IoT platform via MQTT. When the platform-delivered data matches the trigger conditions, the corresponding rule's action list is executed.

TriggerInput SourceCheck TimingSuitable ScenariosCommon Risks
Platform TriggerMQTT platform commandMatch fields immediately upon message arrivalRemote on/off, parameter delivery, linkage controlInconsistent field names, duplicate messageId, insufficient permissions
Timer TriggerLocal clock / cron / intervalExecute when time point is reachedPeriodic reporting, scheduled on/off, night modeNTP not synced, first trigger semantics unclear
Event TriggerButton, sensor, system eventsMatch eventId when event is publishedButton control, threshold alarm, state changeDebouncing, event name spelling, cached value expiry
Poll TriggerActively read peripheral or protocol dataCheck conditions every pollIntervalModbus collection, analog threshold, distance alarmToo frequent, serial port busy, low memory frequency reduction

Platform trigger only evaluates conditions when a platform message arrives; it does not actively read local sensors. If you need to read peripherals at a fixed frequency, use timer or poll trigger instead.

Trigger Mechanism ​

  1. Platform sends data command via MQTT: [{"id":"xxx","value":"yyy"}]
  2. System parses the id and value from the command
  3. Matches triggerPeriphId in the rule against the id in the delivered data
  4. Evaluates conditions using operatorType and compareValue
  5. If conditions are met, triggers rule execution

Field Description ​

FieldTypeDescription
triggerType0Platform trigger
triggerPeriphIdStringData source peripheral ID (matches item.id in delivered data)
operatorTypeuint8Condition operator (see table below)
compareValueStringComparison value

Condition Operators ​

OperatorValueDescriptionExample
EQ0Equalvalue == "1"
NEQ1Not equalvalue != "0"
GT2Greater thanvalue > "30"
LT3Less thanvalue < "10"
GTE4Greater than or equalvalue >= "50"
LTE5Less than or equalvalue <= "100"
BETWEEN6Between"20" <= value <= "80"
NOT_BETWEEN7Not betweenvalue < "20" or value > "80"
CONTAIN8Containsvalue contains "alarm"
NOT_CONTAIN9Not containsvalue does not contain "ok"

BETWEEN operator's compareValue format is "min,max", e.g., "20,80"

Configuration Examples ​

The peripheral execution page is shown below. When configuring platform trigger, verify the MQTT/platform delivered content, comparison value, and target action to avoid accidental triggering of field peripherals.

Example 1: Exact Match (Equal) ​

Scenario: Trigger when platform sends [{"id":"gpio_button","value":"0"}]

Configuration Steps:

  1. Click Peripheral Execution in the left menu

  2. Click the Add Rule button

  3. Fill in basic configuration:

    • Rule Name: Platform Button Trigger
    • Report Data: Enable as needed
    • Enable: ✅ Enabled
  4. Configure trigger:

    • Trigger Type: Select Platform Trigger
    • Target Peripheral ID: Enter gpio_button (match the id in delivered data)
    • Operator: Select Equal (=)
    • Compare Value: Enter 0
  5. Configure actions (add as needed)

  6. Click the Save button

Test Method: Send [{"id":"gpio_button","value":"0"}] via MQTT


Example 2: Threshold Evaluation (Greater Than) ​

Scenario: Trigger when temperature sensor reported value > 35

Configuration Steps:

  1. Create rule, name: Temperature Exceedance Alarm
  2. Trigger configuration:
    • Trigger Type: Select Platform Trigger
    • Target Peripheral ID: Enter dht1
    • Operator: Select Greater Than (>)
    • Compare Value: Enter 35
  3. Configure actions: Add alarm-related actions
  4. Click Save

Test Method: Send [{"id":"dht1","value":"40"}] via MQTT


Example 3: Range Evaluation ​

Scenario: Trigger when humidity value is within 20~80 range

Configuration Steps:

  1. Create rule, name: Humidity Normal Range
  2. Trigger configuration:
    • Trigger Type: Select Platform Trigger
    • Target Peripheral ID: Enter humidity
    • Operator: Select Between (BETWEEN)
    • Compare Value: Enter 20,80 (format: min,max)
  3. Configure actions
  4. Click Save

Test Method: Send [{"id":"humidity","value":"50"}] via MQTT


Method 2: JSON Configuration File Import ​

Complete Rule Example ​

Platform sends restart command to trigger system restart:

json
{
  "id": "exec_platform_restart",
  "name": "Platform Remote Restart",
  "enabled": false,
  "execMode": 0,
  "triggers": [
    {
      "triggerType": 0,
      "triggerPeriphId": "sys_restart",
      "operatorType": 0,
      "compareValue": "1",
      "timerMode": 0,
      "intervalSec": 60,
      "timePoint": "",
      "eventId": "",
      "pollResponseTimeout": 1000,
      "pollMaxRetries": 2,
      "pollInterPollDelay": 100
    }
  ],
  "actions": [
    {
      "targetPeriphId": "",
      "actionType": 6,
      "actionValue": "",
      "useReceivedValue": false,
      "syncDelayMs": 500,
      "execMode": 0
    }
  ],
  "protocolType": 0,
  "scriptContent": "",
  "reportAfterExec": false
}

Precautions ​

  1. ID Matching: triggerPeriphId must precisely match the id field in platform-delivered data
  2. Numeric Comparison: compareValue is parsed as a float for numeric comparison
  3. String Comparison: CONTAIN/NOT_CONTAIN perform substring matching
  4. handleDataCommand: Platform trigger is processed via handleDataCommand method, executes synchronously and returns immediately

FastBee | fastbee.cn