Related: https://www.traccar.org/forums/topic/compare-with-previous-attribute/
Is that it?
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?
You shouldn't use id because it's not set when computed attributes are calculated.
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?
How do you think test works?
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?
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.
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?
In the real processing current will be the newly received position and the last one is the last one, of course.
Okay, that makes sense now. Thanks, man.
Is there a way to access previous Position data from the computed attributes context?