Best strategy to get the difference between pulses in MSR
-
So, I have a rule set that it's triggered when a local variable changes. Since it's tied to my solar production, it could change very frequently, so I've just added a reset delay to calm it down, but it's not working as intended.
What I really need is a way to, let's say, define a percentage and define a variable to understand if the new value has changed +/- 10% before going true.
I've tried a couple of ways, but I'm posting here anyway, in case anyone has found a better way to tackle this. Thanks!
-
There are a couple of things previously discussed, so I won't deep-dive here. But consider the simple case of just keeping the last reference value for the attribute in a local expression (e.g. oldval), getting the new value for the attribute (into newval), and having a third expression to compute the percent difference (
abs((newval-oldval)/oldval*100)
). A single condition then just tests the computed percentage, and if exceeds whatever threshold, set oldval to newval and do whatever else needs to be done.The expression language also contains functions for collecting series data and doing basic maths on the series, with the intention of computing rolling averages and things like that. Those examples comes from Vera Reactor, where people controlled things like bathroom fans using humidity sensors, and wanted to look for sharp changes in humidity seen during showering/bathing (just looking at ambient humidity doesn't work because "normal" is different based on the season or even the day's weather).
-
T toggledbits locked this topic on