[SOLVED] Creating a synthetic variable for pulse counter sensors

Hi

We have sensors such as water meters, wind and rain guages that transmit a pulse count every x minutes. which then needs to be converted to the actual value using current and previous value.

For example for a water meter where each pulse = 1 litter, and the device transmits every 10 minutes.

If the current read is 5500 pulses

and previous read is 5000 pulses

And I want to display the user the rate of water litters/per 10 minutes

The equation of the syntactic variable of litters per 10 minutes should be (5500-5000) * 1.

current - previous * 1(litter).

Is it possible to query the property previous value in the Analytics Engine?

How else would you recommend calculating such result in ubidots?

Hi there, you can make that using the new shift()function, as it is not already on our docs you can see an example below:

Synthethic = {{raw_var}} - shift({{raw_var, -1)

With the example above, you will obtain the last value minus the penultimate value of the raw variable time series.

All the best

Hi Jose

That’s exactly what I was asking for!

it’s always nice to learn that a feature is being added/worked on. Its amazing to discover it’s already there :slight_smile:

Hi

Is it also possible to access the timestamp of the variable in the analytics engine (and the previous one as well?)

here is the equation I have to create (for a wind speed sensor)

((current value - previous value)(2.25/Tsec)) * 0.62137110/36

Tsec = seconds between time of current and previous

So ideally I’ll be able to subtract timestamp in unix seconds as well.

let me know

Hi there, you can access to the raw variable timestamp using the dot (.) operator, your calculus should look like the one below:

{{raw_var}}.timestamp - shift({{raw_var}}.timestamp, -1)

All the best

Hi Jose

I am having issues entering the formula into the synthetic variable of a device. Because I have to also include deviceID, is the correct syntax

{{354043052055631.rssi}}.timestamp - shift({{354043052055631.rssi}}.timestamp,-1) ?

I am trying to test it on an existing device (and not adding it in device type), so it also asks me for device ID, but when I try to either paste it in or create it in the editor, its not working

attempt one

round(({{354043052055631.rssi}} - shift({{354043052055631.rssi}}, -1)) * 2.25/({{354043052055631.rssi}}.timestamp - shift({{354043052055631.rssi}}.timestamp,-1)) * 0.621371*10/36,2)

attempt two

round(({{rssi}} - shift({{rssi}}, -1)) * 2.25/({{rssi}}.timestamp - shift({{{rssi}}.timestamp,-1)) * 0.621371*10/36,2)

neither is working, please advise

Hi there, please make sure that you are selecting your raw variable from the right panel in the synthetic editor

All the best

Ok so there is no way to manually enter deviceID.variable name using syntax like {{deviceID.variable}} ?

For complicated equations such as the one I posted, it is difficult to create it all in-line.

Hi there, it seems that you were assisted through the embedded support chat, so just let me know if you could solve the issue.

All the best

Hi Jose

Yes, David indeed helped me, because my broken syntax was causing issues with device types.

end up this with this syntax in the device type:

round(({{counter}}-shift( {{counter}},-1))(2.25/( {{counter}}.timestamp /1000 - shift( {{counter}}.timestamp,-1)/1000))(0.621371*10/36),2)

and it works

(division by 1000 to convert miliseconds to seconds)