Accessing previous position data from computed attributes

memesaregooda month ago

Is there a way to access previous Position data from the computed attributes context?

memesaregooda month ago
memesaregooda month ago

Sorry if I'm too quick.

I tried using last and it appears that the last position data yields... the latest received position data? All the topics I've found that by using last, one can access the previous attributes data, however in my case id - lastId yields 0, which means id and lastId are the same and so are the position data.

Am I missing something?

Anton Tananaeva month ago

You shouldn't use id because it's not set when computed attributes are calculated.

memesaregooda month ago

The subtraction is valid for other attributes as well. If I use a well-fluctuating value that is power voltage value and subtract current from the last, I will still get 0, which is possible, though very unlikely (current fluctuates too much, and the values should have been different). So I tried on different devices - only to yield 0 from the subtraction, proving that the values are the same.

Am I missing something here?

Image 1
Image 2
Image 3

Anton Tananaeva month ago

How do you think test works?

memesaregooda month ago

Well, I assume that test works by running the expression within the current position context? And if the lastAttributes flag is true in the config file, it adds previous position data in its context too? Did I get that right?

Anton Tananaeva month ago

No, the current position will be the last one. And the last one will be the last one. So it is absolutely expected that those will be the same for testing.

memesaregooda month ago

So, when tested, the current and the last are the same?

Okay. When the computed attribute is actually created and linked to a device, will the last one contain previous Position data?

If not, how does one access old data to compare with in the computed attributes? The user in the thread mentioned managed to get the old fuel value. What am I doing wrong?

Anton Tananaeva month ago

In the real processing current will be the newly received position and the last one is the last one, of course.

memesaregooda month ago

Okay, that makes sense now. Thanks, man.