Integrations

Filter

Spook adds an action to the filter sensor that changes its settings, so an automation can filter harder or softer without a trip to the helper's options.

The filter helper cleans up a noisy sensor. It is one kind of filter: a low-pass filter smooths the value, an outlier filter drops the spikes, a range filter keeps the value between two bounds, a throttle lets only every so many changes through, and a time based moving average averages over a stretch of time.

How hard it filters is set in the helper's options, and only there. An automation cannot change it: not a wider margin for the kitchen temperature while the oven heats up the room, when every honest jump looks like a spike.

Spook adds an action for that: set options.

Actions

Spook adds one action to the filter integration. You find it wherever you add an action, marked with a 👻.

Set options

Changes the settings of one or more filter sensors, like the options of the helper do. What you leave out stays as it is, the sensor it filters and its kind of filter too.

The change goes through the helper's own options, so Home Assistant checks it the same way it checks what you fill in there. Then Home Assistant reloads the sensor, as it does after you save its options. The action returns once the sensor is reloaded, so the next step of your automation already sees it filter with its new settings. A sensor that already has the settings you give is left alone, without a reload.

Which settings a filter has depends on its kind:

Kind of filterIts settings
Low-passWindow size, time constant, precision
OutlierWindow size, radius, precision
RangeLower bound, upper bound, precision
ThrottleWindow size, precision
Time based moving averageWindow size, precision
Time throttleWindow size, precision
  • Window size: how many samples the filter looks at, as a number. For a time based moving average and a time throttle, it is how long instead, as a duration like "00:05:00".
  • Radius: how far a value of an outlier filter may be from the median of its window before the filter replaces it with that median.
  • Time constant: how slowly a low-pass filter follows its source. The higher, the smoother.
  • Lower bound and upper bound: a range filter turns anything below the lower bound into the lower bound, and anything above the upper bound into the upper bound.
  • Precision: the number of decimals the filter rounds its value to.

A setting the filter does not have is refused, with an error that names the filter and its kind: a low-pass filter has no radius. So is a window of the wrong shape: a number of samples for a time throttle, or a duration for a throttle.

A range filter can be without a bound. To take one away, give it null in YAML: lower_bound: null lets anything low through. The options of the helper take no bound below 0, even though a filter set up in YAML does, so neither does Spook. A lower bound above the upper bound is refused too. The options of the helper take it, but the filter checks the upper bound first: anything above it becomes the upper bound, anything else the lower bound, so only those two values would ever come out. Equal bounds are fine.

A window of no samples or no time, and a time constant of 0, are refused. The options of the helper take them, and the filter then has nothing to filter with: a low-pass filter or a moving average divides by them, and fails on every new value.

A sensor with the same name, sensor and settings as another filter is refused by Home Assistant, the same as when you make it twice. The error says so, and names the sensor. It stays as it was.

Every entity is checked before the first sensor changes. An entity that is not a filter sensor, one set up in YAML, one that does not have a setting you give, or a range filter the change would leave with its lower bound above its upper bound, is refused with an error, and nothing changes. The sensors change one at a time, in the order you give them. When Home Assistant refuses the new settings of one, like when they match another filter, the action stops with an error that names that sensor. The sensors before it in the list did change; the ones after it did not.

Run by hand, the action takes an administrator, like the options of a helper do. Your automations can always run it. So can your scripts, unless a user who is not an administrator starts one.

How to use it

  1. Open the automation or script that should change the filter, and select Add action.
  2. Search for set options, and select Filter: Set options 👻.
  3. Choose the filter sensors.
  4. Turn on the settings you want to change, and fill in the new values.
  5. Select Save.

To take a bound away, switch the action to YAML with the three dots menu, and set it to null.

Missing something here?

An action, an entity or a repair this integration should have? Say so. Stuck, or found a bug? There is help.