Ok, not to many examples in other languages I’m working basing on your Filter Profile example. Have some questions as your script is used in Main UI and not sure if I have all the functions available
First I would use in items file as profile
[profile="transform:JS", toItemScript="divide_by_10_and_checkDelta.js" ]
Is that right place?
Then I see you do following
const curr = Quantity(data);
const last = cache.private.get(id, () => curr);
const delta = curr.subtract(last);
data is the incoming value ,yes?
id is the name of the item that I need to call from cache? to get the last (previous) value.
can I pass it in the item definition like below?
[profile="transform:JS", toItemScript="divide_by_10_and_checkDelta.js?id=inverter_PV_Today_energy" ]
Then my function would look like:
(function(data,id) {
var current = parseFloat(data) / 10;
const curr = Quantity(current);
const last = cache.private.get(id, () => curr);
const delta = curr.subtract(last);
if(delta.greaterThanOrEqual(2) || delta.lessThanOrEqual(-2)) {
console.debug('Threshold exceeded, bogus value ' + curr);
return null;
}
else {
cache.private.put(id, current);
return current;
}
})(input,id)
I don’t understand what Quantity() does, just copied it from your example, can it be ommited?
Does that make sense?