Script Actions
Script Actions
Action Types
| Action | actionType | Description |
|---|---|---|
| ACTION_SCRIPT | 15 | Command sequence script |
| ACTION_CALL_PERIPHERAL | 10 | Call peripheral |
Configuration Examples
Method 1: Web Interface Configuration (Recommended)
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:
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 Command Script Script action Script Content See below Multi-line command sequence 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 completeClick 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:
Edit the rule, add an action
Action type: Select Command Script
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 completeClick 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:
Edit the rule, add an action
Action type: Select Command Script
Script content:
MQTT 0 [{"id":"temperature","value":"RANDOMF(15,35,1)"},{"id":"humidity","value":"RANDOMF(30,90,1)"}]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:
Edit the rule, add an action
Fill in:
- Action Type: Select Call Peripheral
- Target Peripheral: Select
dht1 - Call Command: Enter
read
Click Save
Method 2: JSON Configuration File Import
Complete Rule Example
Fan High/Low Speed Operation
{
"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
- Async Execution: Script actions execute in FreeRTOS async tasks, not blocking the main loop
- DELAY Limit: Single DELAY recommended not to exceed 10 seconds; total script execution time recommended not to exceed 60 seconds
- Resource Protection: Heavy-resource rules (scripts/Modbus/multi-action) are skipped when system resources are low (not degraded to sync)
- targetPeriphId: Script action's targetPeriphId is usually empty (PERIPH commands within the script specify the target)
- Build Flag: Full script functionality requires
FASTBEE_ENABLE_COMMAND_SCRIPT=1
