Trigger Example: Aggregating Property Values
A data usage property is published at regular intervals, but the property value is not aggregated. In addition to the data usage, the aggregated data usage also needs to be displayed.
To solve this requirement, the data usage property that is published at regular intervals is used to calculate the aggregate data usage. The aggregate data usage is defined as an additional property.
The thing's thing definition has a property for the data usage. An additional property for aggregate data usage is defined:
-
Property key for data usage: data_usage.
-
Property key for aggregated data usage : data_usage_agg.
-
$(event.thing.key) - The key of the thing that initiated the cloud trigger.
-
$(event.prop.value) - The data value of the published property from the Publish Property action (or property.publish API) that initiated the cloud trigger.
-
$(event.prop.ts) – The timestamp value of the published property that initiated the cloud trigger.
-
$(action.X.value) - The result value for action block X.
The property.current action stores the current value for the data_usage_agg property into the $(action.0.value) action variable. It does this using the $(event.thing.key) event variable for the Thing key parameter.
The math.expr action adds the property value from the event, the published property value $(event.prop.value), to the $(action.0.value) action variable.
-
In the Expression parameter, the operands are the $(event.prop.value) published property value and the $(action.0.value) action variable, which has the current value for the data_usage_agg property. The operand is a "+" for addition.
-
The $(action.0.value) action variable value was set in the previous property.current action.
-
The result of the addition of the $(event.prop.value) and the $(action.0.value) is stored into the $(action.1.value) action variable.
The property.publish action publishes the result of the previous math.expr action:
-
The Value is the $(action.1.value) action variable
-
The Property key is the data_usage_agg property
-
The Thing key is the $(event.thing.key) event variable
-
The Timestamp is the $(event.prop.ts) event variable from the initial cloud trigger event.
-
The trigger event Thing key and Thing tags parameters can be specified to limit which things cause this trigger to execute.
-
The trigger event Operator, Operand, On Edge, and Time in Condition (seconds) parameters can be used to further specify run-time conditions that must be met to have this trigger execute.
-
The Suggestions pick list in the action blocks can be used to select event variables or action variables. The action block number X in an action variable, such as $(action.X.value) refers to the current number of an action block. If actions are inserted and deleted, the reference to action block numbers must be reviewed to ensure they are using the appropriate current action block number for each action.