You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[basicprofiles] Add support for functions (DELTA, MEDIAN, AVG, STDDEV, MIN, MAX) in State Filter (openhab#17362)
* [basicprofiles] Add support for functions (DELTA, MEDIAN, AVG, STDDEV, MIN, MAX) in State Filter
Support any type of operand on either side of the operator
e.g.: `ItemName > 10` and `10 < ItemName`
Signed-off-by: Jimmy Tanagra <[email protected]>
Copy file name to clipboardexpand all lines: bundles/org.openhab.transform.basicprofiles/README.md
+33-9
Original file line number
Diff line number
Diff line change
@@ -198,21 +198,37 @@ Use cases:
198
198
199
199
#### State Filter Conditions
200
200
201
-
The conditions are defined in the format `[ITEM_NAME] OPERATOR VALUE_OR_ITEM_NAME`, e.g. `MyItem EQ OFF`.
201
+
The conditions are defined in the format `[LHS_OPERAND] OPERATOR RHS_OPERAND`, e.g. `MyItem EQ OFF`.
202
202
Multiple conditions can be entered on separate lines in the UI, or in a single line separated with the `separator` character/string.
203
203
204
+
The `LHS_OPERAND` and the `RHS_OPERAND` can be either one of these:
205
+
206
+
- An item name, which will be evaluated to its state.
207
+
- A type constant, such as `ON`, `OFF`, `UNDEF`, `NULL`, `OPEN`, `CLOSED`, `PLAY`, `PAUSE`, `UP`, `DOWN`, etc.
208
+
Note that these are unquoted.
209
+
- A String value, enclosed with single quotes, e.g. `'ON'`.
210
+
A string value is different to the actual `OnOffType.ON`.
211
+
To compare against an actual OnOffType, use an unquoted `ON`.
212
+
- A plain number to represent a `DecimalType`.
213
+
- A number with a unit to represent a `QuantityType`, for example `1.2 kW`, or `24 °C`.
214
+
- One of the special functions supported by State Filter:
215
+
-`$DELTA` to represent the absolute difference between the incoming value and the previously accepted value.
216
+
-`$AVERAGE`, or `$AVG` to represent the average of the previous unfiltered incoming values.
217
+
-`$STDDEV` to represent the _population_ standard deviation of the previous unfiltered incoming values.
218
+
-`$MEDIAN` to represent the median value of the previous unfiltered incoming values.
219
+
-`$MIN` to represent the minimum value of the previous unfiltered incoming values.
220
+
-`$MAX` to represent the maximum value of the previous unfiltered incoming values.
221
+
These are only applicable to numeric states.
222
+
By default, 5 samples of the previous values are kept.
223
+
This can be customized by specifying the "window size" or sample count applicable to the function, e.g. `$MEDIAN(10)` will return the median of the last 10 values.
224
+
All the functions except `$DELTA` support a custom window size.
225
+
204
226
The state of one item can be compared against the state of another item by having item names on both sides of the comparison, e.g.: `Item1 > Item2`.
205
-
When `ITEM_NAME` is omitted, e.g. `> 10, < 100`, the comparisons are applied against the input data from the binding.
227
+
When `LHS_OPERAND` is omitted, e.g. `> 10, < 100`, the comparisons are applied against the input data from the binding.
228
+
The `RHS_OPERAND` can be any of the valid values listed above.
206
229
In this case, the value can also be replaced with an item name, which will result in comparing the input state against the state of that item, e.g. `> LowerLimitItem, < UpperLimitItem`.
207
230
This can be used to filter out unwanted data, e.g. to ensure that incoming data are within a reasonable range.
208
231
209
-
Some tips:
210
-
211
-
- When dealing with QuantityType data, the unit must be included in the comparison value, e.g.: `PowerItem > 1 kW`.
212
-
- Use single quotes around the `VALUE` to perform a string comparison, e.g. `'UNDEF'` is not equal to `UNDEF` (of type `UnDefType`).
213
-
This will distinguish between a string literal and an item name or a constant such as `UNDEF`, `ON`/`OFF`, `OPEN`, etc.
214
-
-`VALUE` cannot be on the left hand side of the operator.
215
-
216
232
##### State Filter Operators
217
233
218
234
| Name | Symbol ||
@@ -247,6 +263,14 @@ Number:Power PowerUsage {
247
263
}
248
264
```
249
265
266
+
Filter out incoming data with very small difference from the previous one:
0 commit comments