Transforming Values

In some cases, RAW data managed by the remote object may use a legacy representation for some types of information.

For instance:

  • The environment temperature can be published as an integer of 4 digits (e.g. 2550 → 25.5 °C).

  • A boolean can be published as integer (e.g. 1 → true, 0 → false).

  • The number of hours can be published by using the number of milliseconds, and for this reason you need to convert back to hours (e.g. value / 3600000).

In order to store the right value, within a Simple metric you can select a Value Transformer, which is applied as the last step during the value extraction from the incoming IoT message.

Value transformer can be used within the definition of:

Predefined Value Transformers

By default, Servitly provides the following Value Transformers:

Transformer

Description

Boolean to Integer

Converts true or false to 1 or 0.

Int / 10

Divides the value by 10.

It is generally used to convert input values encoded as integers but representing a float with a decimal (e.g., 123 → 12.3).

Int / 100

Divides the value by 100.

It is generally used to convert input values encoded as integers but representing a float with two decimals (e.g., 123 → 1.23).

Two’s Complement

Converts to integer a value represented in two’s complement (e.g. 0101 → 5).

Two’s Complement / 10

Converts to integer a value represented in two’s complement and divide by 10 (e.g. 0101 → 0.5).

Two’s Complement / 100

Converts to integer a value represented in two’s complement and divide by 100 (e.g. 0101 → 0.5).

Integer to Boolean conversion is handled automatically by the system, so there is no need for an explicit value transformer.

Custom Value Transformers

You can use one of the predefined value transformers or, in addition, you can create your own one by clicking the Add Value Transformer button.

The Value Transformer creation requires providing:

  • Name: the name that uniquely identifies the transformer.

  • Description: the text that describes the transformer and helps find it when defining a metric.

  • Expression: the mathematical expression to be used to convert the incoming value.
    You can use the default "value" variable, but in addition you can use the context thing and thus the underlying properties. For instance, (value * thing.properties.factor) / 100.