Gravio Action Flow Development Guide
Table of Contents
- 1. Overview of Action Configuration View
- 2. Steps to Create an Action
- 3. Variables and Variable Types Available in Actions
- 3.1 Variable Types and Type Conversion
- 3.2 Operators
- 4. How to Reference Object Data
- 5. Action Component Operation
- 5.1 Input Payload
- 5.2 Output Payload
- 6. Using Pre Mappings / Post Mappings
- 6.1 How to Write Expressions
- 6.2 Available Functions
- 7. Action Execution Flow and Debugging
- 7.1 Debug Log Output
- 7.2 Action Program Processing Order
- 8. File Path Notation
- 8.1 Default Reference/Save Location
- 8.2 Various File Path Notation Methods
- 9. Specifying Attachments
- 9.1 Specifying Attachments in Windows
- 9.2 Specifying Attachments in Mac/Linux/Gravio Hub
1. Overview of Action Configuration View
In the Action Configuration View, you can write programs that are executed by triggers. These programs are called "Actions."
In a typical use case, sensor data triggers multiple actions and passes multiple parameters to those actions.
To create or edit an action, follow these steps: 1. Go to the server overview screen 2. Click the middle icon at the bottom of the server card 3. From the displayed UI, click the "+" mark in the top left menu to add an action
2. Steps to Create an Action
To create a new action:
- Click the "+" symbol in the top right of the Action Configuration View in the edge server
- Enter a name for the action file that will store the new action (e.g.,
NewAction.acs) - Press OK, and the new action file will be registered and displayed in the list
- Double-click the action file to open the action editor
In the action editor, actions are composed of "steps" that are arranged from left to right in the execution sequence.
To add a new step: 1. Click the "+" icon in the top right 2. Select a new action component from the "Action Component Library" 3. After selecting a component, a configuration screen appears where you can configure the step and access or process its variables
3. Variables and Variable Types Available in Actions
The following types of variables can be used within action programs:
Action Property
- Prefix:
ap. - Can be defined as properties passed from outside when the action is executed
Action Variable
- Prefix:
av. - Variables that can be referenced within the action
Component Property
- Prefix:
cp. - Values that determine component behavior
- Example: For HTTPRequest component, properties like
Method(GET/POST etc.) andURL
Component Variable
- Prefix:
cv. - Variables implicitly declared in components
- Example:
cv.StatusCode(HTTP status code in HTTPRequest component)
Trigger Variable
- Prefix:
tv. - Can reference data sent from sensors
- Main trigger variables:
tv.AreaId: Area IDtv.AreaName: Area nametv.LayerId: Layer IDtv.LayerName: Layer nametv.KindId: Data type IDtv.KindName: Data type nametv.PhysicalDeviceId: Sensor's physical device IDtv.PhysicalDeviceName: Sensor's physical device nametv.Timestamp: Time when data was output from sensor (RFC3339Nano format)tv.DataId: Unique ID for this sensor datatv.Data: Sensor data value (same ascv.Payloadof the first component)
Trigger Property
- Prefix:
tp. - Can reference trigger properties set in event triggers or timer triggers within the action
- Example:
tp.KeyAreaName,tp.KeyLayerName,tp.TriggerName
3.1 Variable Types and Type Conversion
Available variable types are:
| Variable Type | Description |
|---|---|
| Int | Integer |
| Double | Floating point |
| String | String |
| Bool | true/false |
| DateTime | Date and time |
| Byte array | Byte array |
| Array | Array |
| Object | Object |
Conversion between types is possible. Conversion rules are defined as follows:
- To Boolean:
- Numeric: false if 0, true otherwise
- DateTime: false if Unix time is 0, true otherwise
- String: true for "true"/"1", false otherwise
- Byte array: follows string rules after conversion to string
-
Other types: false
-
To Numeric:
- Boolean: 1 (or 1.0) for true, 0 (or 0.0) otherwise
- String: follows ParseInt or ParseFloat rules
- DateTime: uses Unix time as numeric value
-
Byte array: follows string rules after conversion to string
-
To String:
- Boolean: "true" for true, "false" otherwise
- Numeric: converts to appropriate string format
- DateTime: converts to RFC3339Nano format
-
Array, Object: converts to string using json.Marshal
-
To DateTime:
- Numeric and Boolean: converts to integer then treats as Unix time
- String: tries multiple date formats in sequence
3.2 Operators
The following operators can be used in action programs:
Arithmetic Operators:
- + Addition
- - Subtraction
- * Multiplication
- / Division
- ** Power
- & Bitwise AND
- | Bitwise OR
- ^ Bitwise XOR
- % Modulo
Comparison Operators:
- > Greater than
- >= Greater than or equal
- < Less than
- <= Less than or equal
- == Equal
- != Not equal
- =~ Regular expression match
- !~ Regular expression non-match
Logical Operators:
- || Logical OR
- && Logical AND
4. How to Reference Object Data
When referencing Object type variable values in actions, use dot notation or bracket notation.
For example, with JSON data like this:
{
"id": "XXXXXX",
"source": {
"channel": 4,
"bacId": "YYYYYY"
},
"common": {
"description": "Face Recognition",
"time": "2019-06-17T07:53:22.986Z"
},
"fr": {
"candidates": [
{
"customId": "00001",
"displayName": "Person B",
"similiarityScore": "0.7272"
}
]
}
}
To reference fr.candidates[0].displayName, use either:
tv.Data.fr.candidates[0].displayName
Or, when key names contain spaces or hyphens:
tv.Data["fr"]["candidates"][0]["displayName"]
tv.Data.fr.candidates[0]["display Name"] // For key names containing spaces
These access methods can also be used in action conditions:
cv.Payload.fr.candidates[0].displayName == "Person B"
They can also be used in trigger conditions. For example, to trigger an action only for males in IVAR:
tv.Data.iod.gender == "MALE"
5. Action Component Operation
Action components provide component variables for input payload (cv.Payload) and output payload (cv.Payload).
5.1 Input Payload
- The "input payload" is the same as the "output payload" of the previous component
- For the first component in an action, the trigger variable (
tv.Data) becomes the input payload (cv.Payload)
5.2 Output Payload
- The "output payload" becomes the "input payload" of the next component
- The content of the output payload is determined by each component's processing
6. Using Pre Mappings / Post Mappings
When selecting a component in the Action Editor screen, the Pre Mappings / Post Mappings editing area appears on the right.
6.1 How to Write Expressions
- Press the "+" button to display the input field
- Write the variable name on the left and the expression to assign to the variable on the right
- Example:
cp.Color = "Blue"
Expressions can include: - Arithmetic operations (+, -, *, /) - Functions - Variables (tp.〜, tv.〜, ap.〜, av.〜, cp.〜, cv.〜, etc.)
The evaluation result type of the right-hand expression is automatically converted to the left-hand type.
You can also use comparison operators to return boolean values:
- Example: cv.Payload > 10
- Example: cv.Payload == "abc"
6.2 Available Functions
Functions available in Pre Mappings / Post Mappings expressions:
String Functions:
Len, Contains, RuneCount, HasPrefix, HasSuffix, Index, Join, LastIndex, Repeat, Replace, Split, ToLower, ToUpper, Trim, TrimLeft, TrimRight, TrimPrefix, TrimSuffix
Type Conversion Functions:
ToBool, ToInt, ToFloat, ToString, ToDate, ToBinary, ToJSON
Encoding Functions:
URLPathEscape, URLPathUnescape, URLQueryEscape, URLQueryUnescape, MD5, SHA1, SHA256, BASE64, DecodeBASE64, BASE64URL, DecodeBASE64URL
Date Functions:
Now, Year, Month, Day, Hour, Minute, Second, Weekday, ToLocal, ToUTC, ToTimezone, DateFormat, DateParse
Environment Variables:
Env
Regular Expression Functions:
RegExpMatch, RegExpFind, RegExpFindSubmatch, RegExpFindAll, RegExpReplace, UUID
7. Action Execution Flow and Debugging
7.1 Debug Log Output
You can output debug logs by pressing the button in the top left of the component. Debug logs display the values of tp/tv/ap/av/cp/cv properties and variables.
7.2 Action Program Processing Order
Action programs are processed in the following order:
- Get component variables including Payload from the queue
- If there are PostMappings values from the previous component, assignment is performed
- PreMappings expressions are evaluated and values are assigned
- Component executes processing according to properties
- Create new component variables including Payload based on component processing results
- PostMappings expressions are evaluated, and result values are stored in new component variables including Payload
- Pass new component variables including Payload to the next component's queue
- Repeat process (return to 1)
When debug log function is ON, variable contents after step 3 (PreMappings evaluation and assignment) are output. This allows you to check variable states at each step.
Note that while components normally operate independently in parallel, when executing actions with debug log output, synchronous processing occurs in the action engine.
8. File Path Notation
Files specified in component properties can use various file path formats. Here's how to write paths for different cases.
8.1 Default Reference/Save Location
The default location varies by OS:
- Windows: C:\ProgramData\HubKit\action\actmgr\data\
- Mac: /Library/Application Support/HubKit/action/scripts/actmgr/data/
- Linux: /var/opt/hubkit/action/scripts/actmgr/data/
8.2 Various File Path Notation Methods
1. Files in data folder
For non-Windows
| File Path | Description |
|---|---|
| sample.txt | Specifies sample.txt in actmgr/data folder |
| ./sample.txt | Specifies sample.txt in actmgr/data folder |
For Windows
| File Path | Description |
|---|---|
| sample.txt | Specifies sample.txt in actmgr/data folder |
| .\sample.txt | Specifies sample.txt in actmgr/data folder |
2. Files with Relative Paths from data folder
For non-Windows
| File Path | Description |
|---|---|
| ../../../../gravio/sample.txt | Specifies gravio/sample.txt 4 levels up from actmgr/data folder |
For Windows
| File Path | Description |
|---|---|
| ..\..\..\..\gravio/sample.txt | Specifies gravio\sample.txt 4 levels up from actmgr/data folder |
3. Files with Absolute Paths
For non-Windows
| File Path | Description |
|---|---|
| /home/gravio/sample.txt | Specifies home/gravio/sample.txt under root |
For Windows
| File Path | Description |
|---|---|
| c:\temp\sample.txt | Specifies temp\sample.txt under c: drive |
Note: These examples assume reading a sample.txt file.
9. Specifying Attachments
Some action components, such as email sending and HTTP sending, handle attachments. Here's how to specify attachments.
Multiple files can be specified as attachments. File path notation differs by OS environment, so follow these guidelines.
9.1 Specifying Attachments in Windows
In Windows, actmgr\data is automatically stored in file paths. Path specification is also possible.
Note: When folder or file names contain spaces, they must be enclosed in " (double quotes).
Basic Examples:
- To attach image.jpg in actmgr\data, specify
image.jpg - To attach image.jpg in actmgr\data\subfolder, specify
subfolder\image.jpg - To attach image.jpg in actmgr\data\subfolder 2021, specify
"subfolder 2021\image.jpg"
Absolute Path Examples:
- To attach image.jpg in c:\, specify
c:\image.jpg
Multiple Files and Wildcards:
You can specify multiple files and use wildcards. Use ; (semicolon) as separator for multiple files and * (asterisk) for wildcards.
- To attach image.jpg and image2.jpg in actmgr\data, specify
image.jpg;image2.jpg - To attach *.jpg in actmgr\data\subfolder, specify
subfolder\*.jpg - To attach image.jpg and image2.jpg in actmgr\data and *.jpg in actmgr\data\subfolder, specify
image.jpg;image2.jpg;subfolder\*.jpg
9.2 Specifying Attachments in Mac/Linux/Gravio Hub
In Unix-based systems, actmgr/data is automatically stored in file paths. Path specification is also possible.
Note: When folder or file names contain spaces, they must be enclosed in " (double quotes).
Basic Examples:
- To attach image.jpg in actmgr/data, specify
image.jpg - To attach image.jpg in actmgr/data/subfolder, specify
subfolder/image.jpg - To attach image.jpg in actmgr/data/subfolder 2021, specify
"subfolder 2021/image.jpg"
Absolute Path Examples:
- To attach image.jpg in /home/username, specify
/home/username/image.jpg
Multiple Files and Wildcards:
You can specify multiple files and use wildcards. Use ; (semicolon) as separator for multiple files and * (asterisk) for wildcards.
- To attach image.jpg and image2.jpg in actmgr/data, specify
image.jpg;image2.jpg - To attach *.jpg in actmgr/data/subfolder, specify
subfolder/*.jpg - To attach image.jpg and image2.jpg in actmgr/data and *.jpg in actmgr/data/subfolder, specify
image.jpg;image2.jpg;subfolder/*.jpg
By using the correct path separators and file specification methods for your OS environment, you can properly specify attachments. Remember to always enclose paths containing spaces in double quotes.