Star

ThingsBoard Documentation

Documentation for using ThingsBoard IoT Platform.

States

Simple state

image

In this example we have Machine device that submit how many details where produced. We want to find what is production rate of our machines.

Let’s define our states:

Here is condition that chack does machine in Low Production state or not:

    double okRate = none(Machine.okDetails);
    return okRate < 75;

Here steps required to do this:

image

image

Our view ready and now we know how much time(in percent) machines spent in different states.

State with multiple fields

image

We can also use multiple fields from different assets\devices to calculate state. In this example we want detect how much time machines spent in critical state. Such visualisation will give an understanding how machine prorforms compered to other machines and when it should be maintained to prevent downtime.

We know that our machines is in critical state when pressure goes up and rotation speed goes down. So let’s find how much time spent in critical state.

Here is a formal definition of Critical state:

    double pressure = none(Machine.pressure);
    double speed = none(Machine.rotationSpeed);
    return pressure > 700 && speed < 35;

State Aggregation

Here is a list of supported aggregation functions for state fields:

Get original field value

Before applying transformation you need to get a reference to the original field value. Here is an example how to do this:

double temp = avg(Machine.temperature);

All 3 parts are required, you can not access original field value without aggregation function.

If original field value is an attribute, entity name or owner name - you should use uniq() aggregation function.

This template can be used for comparing text fields:

String currentState = none(machine.status);
return "running".equals(currentState);

Supported Aggregation Functions

State fields supports following aggregation functions:

Each function allows only 1 argument - reference to the filed on format EntityName.fieldName. For example:

sum(Machine.temperature)

Commonly, states are used for calculating how much time device/asset spent in different states. To get more precise results it is recommended yo use none() aggregation - in this case system will process only raw telemetry to define is device inside defined state or not.

Aggregation function applied to a grouped dataset. Find more details about Grouping and Aggregation in this article

Language

In most cases amount of data analysed during state calculation is big enoguh. To guarantee performance function should be defined using Java language (Java 8).