Filter sensor not working

I collect data from my power meter via a serial interface (which is converted to MQTT). I have som noise which causes some values to be really wrong. Easiest way to fix this is to use the Filter component as data is sent every 5-10 seconds and I only get about 1-2 errors per hour.

This is my filter config:

 sensor:
 # Filtered sensors
   - platform: filter
     name: "filtered elimport"
     entity_id: sensor.import_el
     filters:
       - filter: outlier
         window_size: 1
         radius: 2

This filter uses imported kWh from my meter. My thought is to look at the previous value and if this differs more than 2kWh throw the value away and re-use the last value. This is not working. I get the same value in the filter sensor as the original sensor.
Original sensor:
original
Filtered sensor:
filtered

I tried turning on debug for the filter component but I see nothing in the log at all from this component:

logger:
  default: error
  logs:
    homeassistant.components.sensor.filter: debug

What am I doing wrong?

Try a larger window size. If you get two bad values in a row, with a window size of 1 the second will pass thru

1 Like

According to the documentation, the window size for the filter “outlier” is an integer for the number of states. It is not time. So just comparing the last recieved value should work as I have yet to see two wrong values received right after eachother. Also, averaging two values when the value is ever increasing does not feel right as the mean of those two values will always be lower than the last recieved correct value.

I have made a change to the config to a window size of 5 just to see if it makes a differens. Will report back as soon as I have an outlier.

1 Like

@PeteRage: your suggestion acctualy worked! I do not know why using only one sample would not work though.

I tried to use a window size of 5 and increased the radius to 4 and it does work. It also does what I was affraid of. It averages the last 5 values and records a value slightly lower than the previous value. I do not think this will impact the energy metering though.

I will now try to decrease to a window size of 2 and see if it works.

I still do not get any debug information which would probably be useful to unstand why only using the last value does not work.

Nope, filtering with “outlier” does not do what I want or need it to do (remove new values that are very different from the previous value). I’ll have to find another solution…

That’s unfortunate. I use these to filter out erroneous temperature values that I occasional receive. I stack the filter, first doing a range check then the outlier. Temperatures don’t fluctuate rapidly whereas power usage does - it may be hard to differentiate between a bad reading and the AC coming on.


sensor:
  - platform: filter
    name: "living_room_thermostat_temperature_filter"
    entity_id: sensor.living_room_thermostat_temperature
    filters:
      - filter: range
        lower_bound: 0
        upper_bound: 100
      - filter: outlier
        window_size: 4
        radius: 20

1 Like

@rug having a similar issue with a filter sensor and I cannot see any debug data either, did you find out why the debug information doesn´t work for filter sensors?

Answering my own question just in case anyone arrives here with a similar issue, I just realised this is the correct line to enable debug for filter sensors:

logger:
  default: info
  logs:
    homeassistant.components.filter.sensor: debug