Ubidots Community

[SOLVED] Is it possible to take input from the dashboard and use it to calculate a synthetic variable?

I have a use case that I think would be fairly generic but, I am not getting the expected results.

Use case: An ultrasonic sensor is measuring the distance (in cm) from the top of a tank to the liquid level. I want to have a widget on the dashboard that displays the % full. The formula is straightforward.

Percent = (( Distance to liquid surface - Distance to bottom) / ( Distance when full - Distance when empty) *100

Thing is that I wanted to allow for different installations to have different tanks. So, I created raw variables for Distance to Bottom and Distance when full) and put sliders on the dashboard to allow a user to set the variables. I created a synthetic variable with the formula above which was deemed valid by the formal editor.

Think is that inputing the raw variables using the sliders or sending another data point from the device Never triggers the calculation of the “Percent”


Greetings @chipmc , to perform a calculus between two variables, both variables must have the same timestamp. As you are sending individual values with sliders, it is probably that your raw variables do not meet this requirement. My advise is to use the fill_missing() method in your formula to fill with valid values your synthetic variable operation.

Maybe the expression below makes the trick:

 (fill_missing( Distance to liquid surface - Distance to bottom) / fill_missing(( Distance when full - Distance when empty) *100)

For more information, please refer to this article.

All the bes


Ah yes, makes perfect sense.

I made the following change and now it works perfectly

fill_missing(( (distance-milkempty) / (milkfull-milkempty))*100)

Thank you!