How to reference Object type variables in Actions
When referring to Object type variables in actions, you can access elements using dot notation or square brackets.
Example JSON data from IVAR face recognition:
{
"id":"XXXXXX",
"source":{
"channel":4,
"bacId" : "YYYYYY",
"taskId" : "ZZZZZZ",
"ivarId" : "000000"
},
"common":{
"description":"Face Recognition",
"presentImageTime":"2019-06-17T07:53:22.986Z",
"time":"2019-06-17T07:53:22.986Z",
"type":"FR"
},
"iod":{
"age":"MIDDLE",
"ageRange":[38, 53],
"faceAvailable":true,
"frSuitable":"NA",
"gender":"MALE",
"glasses":"REGULAR",
"groupId":0,
"liveness":"NO_RESULT",
"livenessProbability":"0.0000",
"mask":"NA",
"objectId":649,
"objectType":"FACE",
"occlusion":"NA",
"race":"NA"
},
"fr":{
"candidates":[{
"customId":"00001",
"displayName":"Person B",
"id":"6",
"indentityGroup":"Company A",
"similiarityScore":"0.7272"
}],
"fdrVersion":"60032084",
"indentityGroup":"Set2",
"mmsReturn":"OK"
}
}
To reference fr → candidates → displayName:
tv.Data.fr.candidates[0].displayName
Alternative syntax for keys with spaces:
tv.Data["fr"]["candidates"][0]["display Name"]
tv.Data.fr.candidates[0]["display Name"]
Use in conditions:
cv.Payload.fr.candidates[0].displayName == "Person B"
tv.Data.iod.gender == "MALE"
String Functions
Available string manipulation functions:
Function | Arguments | Description | Example |
---|---|---|---|
Len | Len(s) | Returns length (bytes) of string | Len("abc012漢字") → 11 |
Contains | Contains(s, substr) | Returns true if s contains substr | Contains("abc012漢字", "漢字") → true |
RuneCount | RuneCount(s) | Returns character count | RuneCount("abc012漢字") → 8 |
HasPrefix | HasPrefix(s, prefix) | Returns true if s starts with prefix | HasPrefix("https://www.asteria.com/", "https://") → true |
HasSuffix | HasSuffix(s, suffix) | Returns true if s ends with suffix | |
FirstIndex | FirstIndex(s, substr) | Returns first occurrence position | FirstIndex("abc012漢字", "漢字") → 6 |
Join | Join(a, sep) | Joins array elements with separator | Join(["abc","def"], "-") → "abc-def" |
Replace | Replace(s, old, new[, n]) | Replaces old with new n times | |
Split | Split(s, sep[, n]) | Splits string by separator | Split("a,b,c", ",") → ["a", "b", "c"] |
ToLower | ToLower(s) | Converts to lowercase | |
ToUpper | ToUpper(s) | Converts to uppercase | |
Trim | Trim(s[, cutset]) | Removes characters from both ends | Trim(" abc ") → "abc" |
Sprintf | Sprintf(format, s) | Formats string with placeholders | Sprintf("Count: %d", ToInt(cv.Payload)) |
JSONPath | JSONPath(path, s) | Extracts value using JSONPath | JSONPath("$.store.book[*].author", cv.Payload) |
IFS | IFS (condition1, value1[, ...]) | Evaluates conditions in order | IFS (ToFloat(cv.Payload) >= 10, "10 or more", true, "Less than 10") |
Sprintf Usage
Formats strings with specified format specifiers.
Specifier | Description |
---|---|
%b | Binary integer |
%d | Decimal integer |
%x %X | Hexadecimal |
%e %E | Scientific notation |
%f %F | Floating point |
%g %G | Compact floating point |
%s | String |
%% | Literal % |
Examples
Sprintf("Message count: %d", ToInt(cv.Payload))
Sprintf("Value: %.2f", cv.Payload)
Regular Expression Functions
Available regular expression functions:
Function | Arguments | Description | Example |
---|---|---|---|
RegExpMatch | RegExpMatch(re, s) | Returns true if pattern matches | RegExpMatch("G.*o", "Gravio HubKit") → true |
RegExpFind | RegExpFind(re, s) | Returns first match | RegExpFind("i.", "Gravio HubKit") → "io" |
RegExpFindSubmatch | RegExpFindSubmatch(re, s) | Returns match with subgroups | RegExpFindSubmatch("(G.*o) (H.*t)", "Gravio HubKit") → ["Gravio HubKit", "Gravio", "HubKit"] |
RegExpFindAll | RegExpFindAll(re, s[, n]) | Returns all matches | RegExpFindAll("i.", "Gravio HubKit") → ["io", "it"] |
RegExpReplace | RegExpReplace(re, s, repl) | Replaces matches with replacement | |
UUID | UUID([sep]) | Generates UUID string |
JSONPath() Usage Examples
JSONPath can be used to extract values from JSON data.
Sample Data
{ "store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
Example usage:
JSONPath("$.store.bicycle.color", cv.Payload)
→ "red"
JSONPath("$.store.book[*].author", cv.Payload)
→ all authors
JSONPath Operators
Operator Description
$ Root object
@ Current object
. or [] Child operator
.. Recursive descent
* Wildcard
[,] Union operator
[start:end:step] Array slice
?() Filter expression
Debug Log
Press the button at the top left of a component to output debug logs.
Debug logs show tp/tv/ap/av/cp/cv properties and variables in order.
Action program processing order:
- Retrieve component variables with Payload from queue
- Process PostMappings values from previous component
- Evaluate and assign PreMappings expressions
- Component performs its processing
- Create new component variables with new Payload
- Evaluate PostMappings expressions only
- Send new variables to next component's queue
Gravio Sensors
Sensor | Collection Method | Frequency | Configuration |
---|---|---|---|
Climate Sensor | Event driven | Once per hour, or when temp ±0.5°C, humidity ±6%, pressure ±25Pa | Not configurable |
Motion Sensor | Motion detection | On motion, then 1-minute sleep | Not configurable |
Door Sensor | Magnetic sensor | On open/close, then 1-minute sleep | Not configurable |
Vibration Sensor | Vibration detection | On vibration, then 1-minute sleep | Not configurable |
Sound Sensor | Microphone | On sound (1 sec), then 1-minute sleep | Not configurable |
Light Sensor | Light detection | On brightness change beyond threshold | Threshold configurable |
Acceleration Sensor | 3-axis accelerometer | On acceleration beyond threshold | Threshold configurable |