How to integrate Altair SmartCore with InitialState.

0. Introduction

By using the Altair SmartCore External API, you could send data to InitialState for monitoring your metrics. A real time visualization of your key performance indicators. Can you imagine the possibilities of this?.

TOP

1. How to use

To send data to InitialState with Altair SmartCore, the first step you have to do is create your InitialState account. Try it for free! If you already have an account you could use it. Login into InitialState. Remember to first create a Streaming event Bucket. If you don't know how, click here.

In this tutorial we will follow a simple example. Our goal is to represent the wind direction graphically.

Range Values

The following table shows the ranges of degrees used to define each orientation:


Orientation Degrees
N - North [0 - 23], [337 - 359]
NE - North East [24 - 66]
E - East [67 - 113]
SE - South East [114 - 156]
S - South [157 - 203]
SW - South West [204 - 246]
W - West [247 - 293]
NW - North West [294 - 336]


  • Wind directions

Then suppose we are receiving wind direcction data from an external device in Altair SmartCore:

  • Data received in Altair SmartCore

Using Listener

We want to push the wind direction to InitialState service when receiving the data.

To create a listener click on "Listeners" Menu option, inside "Rules". Then click on "New" button and create the listener. To know more about it, you could see the tutorial How to create a listener.

Fill the fields with the following values and save the new listener:

  • Name: The name that you prefer
  • Description: The description that you prefer
  • Entity type: Device
  • Entity id: Your id device
  • Event to listen: data_presited
  • If expression: true
  • Then expression:
    import com.altair.sc.utils.BasicHttp;

    def basicHttp = new BasicHttp();

    basicHttp.url ="https://groker.initialstate.com/api/events";
    basicHttp.verb ="POST";

    def access_key = "YOUR ACCESS KEY HERE";
    def content_type = "application/json";
    def bucketKey = "YOUR BUCKET KEY HERE";

    // Wind dir
    map= ["X-IS-AccessKey" : access_key,
    "X-IS-BucketKey": bucketKey,"Content-Type":content_type];
    basicHttp.headers=map;

    def emoji_wind_dir = "";
    def letter_wind_dir = "";

    int value_wind_dir = context.data.wind_dir.toInteger();

    if((value_wind_dir>=0 && value_wind_dir<=23) || (value_wind_dir>=337 && value_wind_dir<=359)){
    emoji_wind_dir = ":arrow_up:";
    letter_wind_dir = "N";
    } else if(value_wind_dir>=24 && value_wind_dir<=66){
    emoji_wind_dir = ":arrow_upper_right:";
    letter_wind_dir = "NE";
    } else if(value_wind_dir>=67 && value_wind_dir<=113){
    emoji_wind_dir = ":arrow_right:";
    letter_wind_dir = "E";
    } else if(value_wind_dir>=114 && value_wind_dir<=156){
    emoji_wind_dir = ":arrow_lower_right:";
    letter_wind_dir = "SE";
    } else if(value_wind_dir>=157 && value_wind_dir<=203){
    emoji_wind_dir = ":arrow_down:";
    letter_wind_dir = "S";
    } else if(value_wind_dir>=204 && value_wind_dir<=246){
    emoji_wind_dir = ":arrow_lower_left:";
    letter_wind_dir = "SW";
    } else if(value_wind_dir>=247 && value_wind_dir<=293){
    emoji_wind_dir = ":arrow_left:";
    letter_wind_dir = "W";
    } else if(value_wind_dir>=294 && value_wind_dir<=336){
    emoji_wind_dir = ":arrow_upper_left:";
    letter_wind_dir = "NW";
    }

    basicHttp.payload ='[{"key":"Wind Direction","value":"' + value_wind_dir + ' - ' + letter_wind_dir + ' ' + emoji_wind_dir + '"}]';
    basicHttp.send();
  • Then rule: leave empty
  • Else expression: leave empty
  • Else rule: leave empty

Be sure to have your listener enabled if you want it to be executed.

2. Examples

  • Last Value
  • Bar Graph
  • Last Value
  • Bar Graph Creation
  • Bar Graph

3. Public view examples

Initialstate offers you the possibility to publish your dashboard publicly.

  • Public view builder
  • Sharing your public dashboard

You can see a simple example of our public dashboard HERE.

From now on you can add other widgets and send more data to complete your public dashboard:

  • More complete dashboard

TOP