Ubidots Community

Synthetic Variable: Current value - Previous Value

Hi there,

I have a simple device running an interrupt function with a variable counting the total integers. Each timestamp or dot produces an increasing integer value. I am trying to create a simple synthetic variable to count the interrupts since the previous timestamp. Im having trouble understanding the syntax of retrieving the previous count value.

i.e: count since last timestamp = latest interrupt count - previous interrupt count

thanks

Hello @rowanb

I hope this note finds you well.

Indeed Advanced Synthetic Variables have a function called shift() which does exactly what you are trying to do, use the current or previous value. The way it is structured is as follows:

shift({{variable-label}},{{number of steps backward}})

For example: If my previous value for a certain variable labeled example were 2, 4, and 6, where the last value is 2.

shift(example, -1) would give the value 4
shift(example, -2) would give the value 6.

For your case the synthetic variable should be as follows:
{{variable}} - shift({{variable}},-1)

Furthermore, please keep in mind that Ubidots STEM doesn’t include Advanced Synthetic Variables as it is only included in our paid plans. Please refer to the following article to see the limits and capabilities of Ubidots STEM.

Hi Sebastian,

Thanks for the reply, that helps clear things up. It looks like I did have variable correct, however did not pick up that the Advanced Synthetic Variables are not available on the STEM licensing. I did have some simple variables working, however not this one. Every time I ran the variable I would get the following error.
Capture
‘Oops! An error occurred and the Variable couldn’t be created’

Perhaps a specific error response to the licensing could help?

Hi @rowanb,

I’m glad it did help clear things up. Thank you for the suggestion, we are going to take into account modifying the pop-up message so it clarifies what exactly is the error.

Best,
-Sebastian