[Solved] Condition for Indicator block

handlebars
dashboard

#1

I’m trying to set a special condition in a query for an indicator block to display value0.
This is the data from my payload"

data": {
    "limit2": 0,
    "limit1": 1,
    "limit0": 4,
    "value2": "11",
    "value1": "76",
    "value0": "81",

I would like to set conditions like this in a query: {{value-0}} > {{ data.limit0}} .
I cannot use something like this:{{value-0}} > 90 or wherever other static value.

This condition does not work {{value-0}} > {{ data.limit0}} neither {{value-0}} > {{ limit0}}
How can I do that?
Thank you.


Retrieve value from slider
#2

Hello!

It looks as though you are attempting to compare a string and a number, which are not comparable.

If you’d like to compare the string and the number in the indicator block, you can accomplish it like so:

String and Number Block Comparison
I have a device with two attributes: airflow and humidity. Airflow is a string, and humidity is a number, so my state reads like this:

As you can see, airflow is less than humidity, but they are not yet comparable as airflow is a string. Within my indicator block, I have set humidity to value-0, and airflow to value-1.


To compare these two, I must change value-1, which is currently a string, to a number. To accomplish this, I use a helper within my indicator block called “add” which casts both values as numbers and adds them. I “add” zero to my string, and the string is now a number that is comparable with value-0!

Which gives me this in my indicator block:

Hopefully this helps!
Julia


#3

Hi Julia
Thank so much for your suggestion.
I implemented it in the way I show in the attached pic but does not work, always the indicator block remain as green even limit0 is in the payload.


Also I tries this {{ value-0}} > {{ add 0 data.limit0}} and {{value-0}} <= {{add 0 data.limit0}}

Please clarify me this: {{ value-0}} >90 this condition does work , so {{value-0}} should be a number !
Thanks for your time


#4

Hi,

I am looking for a little more clarification to troubleshoot your problem.

Could you upload a screenshot of the above “Block Data” section with all of your set Queries?

Thanks!
Julia


#5

Thanks Julia:slightly_smiling_face:


#6

Hello,

Thanks for the screenshots!

I am seeing a couple things here.

The first is that variables are only available when they are pulled in within the Block Data section. You are pulling in attribute “value0” at Query 0 and it’s value is then available at {{value-0}}. To use “limit0”, you will need to do the same thing, as shown below:

You will then be able to use the “limit0” value, and it is accessible at {{value-1}}. I replicated your use case, and this is what it ended up looking like:

The last difference between this case and yours, is that you have your “duration” set to “live stream,” so data will only show when it is live. I have set mine to “last received data point” so it will show the last available value for the data.

Hopefully this helps,
Julia


#7

The last suggestion you gave me does work, thank you.
There is a down side, which is that {{value-1}} is not updated despite
I can see it in the debug tab that its value, limit0 is being updated constantly.
I can verify that the indicator block works, because I set {{value-0}} to a lower value that {{limit-1}}
and the block color get green.
In addition I set up duration to "Last received data point ", otherwise the block does not change the color.
The value that take value-1 is current value it has at the time I create query 1.
After that I move the slider and set the value but nothing happens.


#8


#9

Hi,

I took a look at your workflow and it looks as though you are never updating the value of limit0. Inside of your device state node, you are only setting the state of three attributes within your device: value0, value1, value2. See below:

To remedy this, you will need to include a value for limit0, just as you have with value0, then your Indicator Block will function properly.

Thanks!
Julia


#10

Julia you are awesome !
The blocks are working :slightly_smiling_face:
I did not get the Losant University degree yet !!!
Thank you very much