Accessing previous position data from computed attributes

memesaregood2 months ago

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

memesaregood2 months ago
memesaregood2 months 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 Tananaev2 months ago

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

memesaregood2 months 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 Tananaev2 months ago

How do you think test works?

memesaregood2 months 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 Tananaev2 months 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.

memesaregood2 months 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 Tananaev2 months ago

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

memesaregood2 months ago

Okay, that makes sense now. Thanks, man.