Skip to content

Script Actions ​

Action Types ​

ActionactionTypeDescription
ACTION_SCRIPT15Command sequence script
ACTION_CALL_PERIPHERAL10Call peripheral

Configuration Examples ​

The peripheral execution page is shown below. When configuring script actions, verify script content, execution time, and whether the target peripheral exists.

Script actions are recommended to only carry short action sequences; first confirm that the target peripheral is controllable with a single command, then add delays and multi-step actions to avoid long scripts blocking the execution queue.

Example 1: Flowing Light Effect ​

Scenario: Light up LED1→LED2→LED3 sequentially, 500ms delay each

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 Command ScriptScript action
    Script ContentSee belowMulti-line command sequence
  4. Enter in the script content (one command per line):

    PERIPH led1 HIGH
    DELAY 500
    PERIPH led1 LOW
    PERIPH led2 HIGH
    DELAY 500
    PERIPH led2 LOW
    PERIPH led3 HIGH
    DELAY 500
    PERIPH led3 LOW
    LOG Flowing light cycle complete
  5. Click the Save button

💡 Tip:

  • Commands separated by newlines
  • PERIPH command format: PERIPH <peripheral ID> <action> [parameters]
  • DELAY unit is milliseconds

Example 2: PWM Gradient Control ​

Scenario: Motor accelerates from 0 to maximum, then decelerates to 0

Configuration Steps:

  1. Edit the rule, add an action

  2. Action type: Select Command Script

  3. Script content:

    PERIPH motor_pwm PWM 0
    DELAY 1000
    PERIPH motor_pwm PWM 2048
    DELAY 2000
    PERIPH motor_pwm PWM 4095
    DELAY 3000
    PERIPH motor_pwm PWM 0
    LOG Motor run complete
  4. Click Save

💡 Tip: PWM value range depends on peripheral configuration (8-bit 0-255, 12-bit 0-4095)


Example 3: MQTT Report Test Data ​

Scenario: Periodically report random temperature/humidity data for testing

Configuration Steps:

  1. Edit the rule, add an action

  2. Action type: Select Command Script

  3. Script content:

    MQTT 0 [{"id":"temperature","value":"RANDOMF(15,35,1)"},{"id":"humidity","value":"RANDOMF(30,90,1)"}]
  4. Click Save

💡 Tip:

  • MQTT command format: MQTT <qos> <payload>
  • RANDOMF(min,max,decimals) generates random float
  • RANDOM(min,max) generates random integer

Example 4: Call Other Peripherals ​

Scenario: Directly call DHT11 sensor read

Configuration Steps:

  1. Edit the rule, add an action

  2. Fill in:

    • Action Type: Select Call Peripheral
    • Target Peripheral: Select dht1
    • Call Command: Enter read
  3. Click Save


Method 2: JSON Configuration File Import ​

Complete Rule Example ​

Fan High/Low Speed Operation ​

json
{
  "id": "exec_fan_script",
  "name": "Fan Script Operation",
  "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": "",
      "actionType": 15,
      "actionValue": "PERIPH motor_pwm PWM 4005\nDELAY 5000\nPERIPH motor_pwm PWM 4095\nDELAY 5000\nPERIPH motor_pwm PWM 0\nLOG Fan high/low speed run once",
      "useReceivedValue": false,
      "syncDelayMs": 0,
      "execMode": 0
    }
  ],
  "protocolType": 0,
  "scriptContent": "",
  "reportAfterExec": true
}

Precautions ​

  1. Async Execution: Script actions execute in FreeRTOS async tasks, not blocking the main loop
  2. DELAY Limit: Single DELAY recommended not to exceed 10 seconds; total script execution time recommended not to exceed 60 seconds
  3. Resource Protection: Heavy-resource rules (scripts/Modbus/multi-action) are skipped when system resources are low (not degraded to sync)
  4. targetPeriphId: Script action's targetPeriphId is usually empty (PERIPH commands within the script specify the target)
  5. Feature State: Script actions require FASTBEE_ENABLE_COMMAND_SCRIPT=1 and active commandScript/ruleScript runtime features

FastBee | fastbee.cn