Use virtual button to set current value as origin

I have a Particle device sending gyro data along with battery and charging state every 10 mins. I would like to be able to set incoming value as the new 0 using a virtual button once the device is set on what I want to monitor. I would then like to measure and display the difference between the Origin I set and the current value from the device to monitor any movement. I have tried a few different work flows but have not been able to crack this nut.

Hi @Eddie_Elsenburg,

If I am understanding your question correctly, it sounds as though you are looking to trigger a Virtual Button to store the last value as a “new 0” value and compare incoming data to this “new 0.”

I would recommend using Workflow Storage to store your “new 0” value. Workflow Storage has two nodes to allow you to store the value and get the value, and with that in mind I would recommend a workflow structure like the following for your Virtual Button:

Using a Gauge Query Node, I get the last reported value from the device.

I then store this value in Workflow Storage using the Storage: Set Value Node, and am able to see the value was successfully stored:

Within your Particle workflow, where you would be comparing the incoming values to your new zero, you would use the Storage: Get Value Node to retrieve the stored value. After retrieving this value, you could perform some Math Functions to compare the incoming value with the stored value:

Please let me know if your use case differs from this, or if you have any further questions. :smile:

Thanks!
Julia

Thank you Julia, following your guidance, I was able to get farther along…but I am having some difficulties.

My current work list for my project;
Receive X,Y, and Z data from a gyroscope. (Done)

Save value via the Virtual Button (Mostly done - This is what I get “newZzero {“time”:“2019-11-22T23:02:16.236Z”,“value”:“81.06”} JSON”) Makes it really difficult to do math with the time stamp in there.

Subtract using the math node (will be easier if time stamp isn’t there)

Display in gauge graph the difference between saved value and current value.

Allow user defined alerts for values over a certain degree of rotation.

Hi @Eddie_Elsenburg,

Could you provide a screenshot of the math functions you are performing? I am curious to see your use case so that I can suggest the best solution for operating around the timestamp.

Thanks!
Julia

Ok so I have been working on this and thought I figured it out but nope! screen%20shot|690x381

Hi @Eddie_Elsenburg,

I can definitely understand the frustration here! Currently, your JSON structure is like the following:

{
  "data": {
     "zset": {
        "value": "81.06",
        “time”:“2019-11-22T23:02:16.236Z”
      }
     "xset": {
        "value": "another value",
        “time”:“2019-11-22T23:02:16.236Z”
      }
...
}

Within your Math Node, you are referencing {{data.zset}}, but have expressed the need for only the value in order to do subraction. If you would like to access only the value, and not the time, you can do so by referencing {{data.zset.value}}. Since you have an object below zset, you can reference both the time and value separately.

As a quick tip, it can sometimes be difficult to correctly reference object data, but by implementing a Debug Node, you can easily copy and paste payload paths. You can read more in our Tuesday Tip.

Please let me know if I can assist further.

Thanks so much!
Julia

Thanks JuliaKempf,
Funny thing I woke up this morning at 3am with the very solution you posted. Now on to trying to get the data set to carry over to the dashboard to use in a gauge. I added the data.ydiff to the Attribute on device state but it doesn’t show up in the dropdown on the gauge. On to the research.

1 Like