Cloud trigger: Data conversion

Use Case

A data property is published in imperial units (miles). A subset of customers need this data in metric units (kilometers).

To solve this requirement, the data property published in imperial units is converted to the equivalent metric units and stored in an additional property.

Thing Definition

The thing's thing definition has a property for the imperial units data. An additional property for the metric units data is defined:

  • Property key for Miles per Hour: mph
  • Property key for Kilometers per Hour: kph

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 Publish Property action (or property.publish API) that initiated the cloud trigger.

Action Variables

  • $(action.X.value) - The result value for action block X.

Property.change cloud trigger event

A cloud trigger is executed when a property change occurs for the mph property for all things that have this thing definition and are tagged acme.

The customers who need to see property values in metric units will have tags added to their things and these tags will need to be added to the trigger.

Math.expr action

The cloud trigger does a math.expr action to multiply the mph property value from the event variable $(event.prop.value) by 1.60934 to convert MPH to KPH.

Property.publish action

The value from the math expression action stored in $(action.0.value) is then published to the kph property key for the thing that originally had the mph property published. The thing key is known by using the event variable $(event.thing.key).

Note: The $(action.X.value) action variable references the action block numbered X. In this case we are using 0, as it is the action number from the previous math.expr action (circled in red in the image).

Properties graphs

You can see the end result is having the data in both a mph property and a kph property.

Thing definition presentation characteristics

If you have users who do not need to view the metric unit (kph)property and do not want to see the metric units property displayed with no values, you can edit the thing definition and set the “Show/hide unset properties” to “Hide”. Security tags on the properties in the thing definition combined with custom roles could also be used to “hide” properties that users (with those custom roles) do not need to see.