How to compare string values

How to compare string values

@Gabriel Lenz

In this tutorial, we will learn how to compare string values in a blueprint dashboard.


Some of TagoIO’s widgets allow users to run formulas on a specific value. It can be used to show a more user-friendly value, or change an internal code for a word.


In any case, we can use a formula to change the way that the final user will see the data on their dashboard.


In this example, we will display the value of a variable in a Card widget, and in a Chart widget.


Card widget

To create the card widget we will be using the “device_status” variable.


You can see that without a formula it will show the variable value, but that is not what we want the final user to see.


Let’s say that if the value of the variable is “on”, we will want to display an Online text, and case it is different, we will show Offline.


To do that we need to add a formula to our widget.


Click on the pencil icon located at the top right corner to turn on the edit mode on the dashboard. After, click on the three dots icon on the Card widget.


Now we are at the widget edit panel.

First of all, let’s change the widget title to Device status.


Then we can go to Options and disable both “Show variable names” and “Show mini-chart”.


This already makes our widget prettier.


Now on the “Formula and unit” section, click on “Enable formula”.


Make sure that your source has the “Fixed” button.


Now we just have to do our comparison.


For this example the code will be:

  1. equalText("$VALUE$", "on") ? "Online" : "Offline"

Change it accord your needs.


Keep in mind that if you are not comparing a string value, you need to remove the quotation marks from the .


Now just click on save and we are done.


Here is the end result of the card widget.
image

Chart widget

For the chart example let’s use the “lamp_status” variable.


Let’s say that if the value of the variable is “on”, we will want the chart to read it as 1, otherwise, it should read it as 0.


First, let’s change the title to Lamp status history.


On the “Data from” section, select the variable that you are storing the data of the lamp, in our case, it will be “lamp_status”. Then click on the Gear icon on the top right corner of the “Data from” section. It will open the “Visual” and the “Formula and unit” section. Click on the last one.


There, click on “Enable formula”, and insert the following code:

  1. equalText("$VALUE$", "on") ? 1 : 0


Now click return to the main area of the chart widget panel and go to the “Visual” section.

There click on the “Step” button on the “Line shape” option. Then just click on the create button and we are done.


Here is the end result: