Cloud trigger: Aggregating property values

Use case

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.

Thing definition

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.

Cloud trigger variables

Event Variables
  • $(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 Variables
  • $(action.X.value) - The result value for action block X.

Property.change cloud trigger event

This cloud trigger is executed when a property change occurs for the data_usage property for all things that have this thing definition.
All things that have this thing definition are involved because the Thing key and Thing tags parameters are not specified to limit which things cause this trigger to execute.

Property.current action

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.

Note: The $(action.X.value) action variable references the action block numbered X. In this case we are using 0 as it represents action block 0 for this property.current action (circled in red in the image).

Math.expr action

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.


Property.publish action

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.




Properties graphs

Your graphs for the data usage property (data_usage) and the aggregate data usage property (data_usage_agg) can be viewed.

Additional concepts

  • 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 runtime 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.