Invalid config for 'filter' from integration 'sensor' + invalid option for 'sensor.filter', check: filters

Hello, I am new to HA and for a while now I have problems that energy consumption sensors are creating occasionally wrong readings - exorbitant high positive and/or negative values. I tried to restrict my energy sensors to a certain range with allowed min/max values in the configuration.yaml.

I have googled other posts with this similar problem but I could’t understand the code properly and also couldn’t apply their solutions to my problem.

That are my configuration warnings from developer settings-YAML:

Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 20: not a valid value for dictionary value 'filters->1->filter', got 'out_of_range'
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 21: 'low' is an invalid option for 'sensor.filter', check: filters->1->low
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 22: 'high' is an invalid option for 'sensor.filter', check: filters->1->high
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 31: not a valid value for dictionary value 'filters->1->filter', got 'out_of_range'
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 32: 'low' is an invalid option for 'sensor.filter', check: filters->1->low
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 33: 'high' is an invalid option for 'sensor.filter', check: filters->1->high
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 42: not a valid value for dictionary value 'filters->1->filter', got 'out_of_range'
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 43: 'low' is an invalid option for 'sensor.filter', check: filters->1->low
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 44: 'high' is an invalid option for 'sensor.filter', check: filters->1->high
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 53: not a valid value for dictionary value 'filters->1->filter', got 'out_of_range'
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 54: 'low' is an invalid option for 'sensor.filter', check: filters->1->low
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 55: 'high' is an invalid option for 'sensor.filter', check: filters->1->high
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 64: not a valid value for dictionary value 'filters->1->filter', got 'out_of_range'
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 65: 'low' is an invalid option for 'sensor.filter', check: filters->1->low
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 66: 'high' is an invalid option for 'sensor.filter', check: filters->1->high

Here’s my configuration.yaml:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sensor:
  - platform: filter
    name: "Bitshake Aktueller Verbrauch"
    entity_id: sensor.bitshake_smartmeterreader_mt175_power_curr
    filters:
      - filter: time_simple_moving_average
        window_size: 10
        precision: 1
      - filter: out_of_range
        low: 0
        high: 7000

  - platform: filter
    name: "Bitshake Einspeisung"
    entity_id: sensor.bitshake_smartmeterreader_mt175_total_out
    filters:
      - filter: time_simple_moving_average
        window_size: 10
        precision: 1
      - filter: out_of_range
        low: 0
        high: 200

  - platform: filter
    name: "Bitshake Verbrauch"
    entity_id: sensor.bitshake_smartmeterreader_mt175_total_in
    filters:
      - filter: time_simple_moving_average
        window_size: 10
        precision: 1
      - filter: out_of_range
        low: 0
        high: 50000

  - platform: filter
    name: "BKW aktuell"
    entity_id: sensor.tasmota_energy_power
    filters:
      - filter: time_simple_moving_average
        window_size: 10
        precision: 1
      - filter: out_of_range
        low: 0
        high: 600

  - platform: filter
    name: "BKW heute"
    entity_id: sensor.tasmota_energy_today
    filters:
      - filter: time_simple_moving_average
        window_size: 10
        precision: 1
      - filter: out_of_range
        low: 0
        high: 10

I’d be ever so greatful if someone could help me a working configuration.yaml.

Thank you

no one can help you find the problem since you didn’t format your yaml code properly.

edit the above and place three backticks (```) on the line above and below the code block.

1 Like

Hello finity,
done, thank you very much for the info
kind regards

My guess is that you asked some sort of AI to produce the code for you, yes?

Here is the documentation for the filter integration:

Note:

filter string Required
Algorithm to be used to filter data. Available filters are lowpass, outlier, range, throttle, time_throttle and time_simple_moving_average.

No mention of the out_of_range from your code. Where did that come from? I suspect you want range.

1 Like

I was literally just going to ask the same question.

Hello, yes, I used Chatgpt hoping that I’d get a better result after trying it myself with this code here I patched togehter after googling various similar posts, sadly didn’t work and I didn’t know why.

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

sensor:
  - platform: template
    sensors:

      bitshake_aktueller_verbrauch:
        friendly_name: "Bitshake Aktueller Verbrauch"
        device_class: Power
        unit_of_measurement: W
        state: >
          {% set value = states('sensor.bitshake_aktueller_verbrauch')|float %}
          {% if 0 <= value <= 7000 %}
            {{ value }}
          {% else %}
            unknown
          {% endif %}
        availability: "{{ states('sensor.bitshake_aktueller_verbrauch') not in ['unknown', 'unavailable'] }}"

      bitshake_einspeisung:
        friendly_name: "Bitshake Einspeisung"
        device_class: energy
        unit_of_measurement: kWh
        state: >
          {% set value = states('sensor.bitshake_einspeisung')|float %}
          {% if 0 <= value <= 200 %}
            {{ value }}
          {% else %}
            unknown
          {% endif %}
        availability: "{{ states('sensor.bitshake_einspeisung') not in ['unknown', 'unavailable'] }}"

      bitshake_verbrauch:
        friendly_name: "Bitshake Verbrauch"
        device_class: energy
        unit_of_measurement: kWh
        state: >
          {% set value = states('sensor.bitshake_verbrauch')|float %}
          {% if 0 <= value <= 50000 %}
            {{ value }}
          {% else %}
            unknown
          {% endif %}
        availability: "{{ states('sensor.bitshake_verbrauch') not in ['unknown', 'unavailable'] }}"

      tasmota_energy_power:
        friendly_name: "Tasmota ENERGY Power"
        device_class: Power
        unit_of_measurement: W
        state: >
          {% set value = states('sensor.tasmota_energy_power')|float %}
          {% if 0 <= value <= 600 %}
            {{ value }}
          {% else %}
            unknown
          {% endif %}
        availability: "{{ states('sensor.tasmota_energy_power') not in ['unknown', 'unavailable'] }}"

      tasmota_energy_today:
        friendly_name: "Tasmota ENERGY Today"
        device_class: energy
        unit_of_measurement: kWh
        state: >
          {% set value = states('sensor.tasmota_energy_today')|float %}
          {% if 0 <= value <= 10 %}
            {{ value }}
          {% else %}
            unknown
          {% endif %}
        availability: "{{ states('sensor.tasmota_energy_today') not in ['unknown', 'unavailable'] }}"

I am aware of that linked Filter webpage from HA but I didn’t know how to apply it to solve my problem. That’s why I reached out hoping that someone could provide a solution for me.

Ok, so rather than us wasting our time trying to fight our way through idiot robot vomit, explain what you already have including entity IDs; and what you want to improve.

Sure, thank you very much. I just post here anything I could find and think it’s useful.

My smart meter has 3 sensors:

sensor.bitshake_smartmeterreader_mt175_power_curr
sensor.bitshake_smartmeterreader_mt175_total_in
sensor.bitshake_smartmeterreader_mt175_total_out

In order to make these sensors appear in the energy dashboard I had to create 3 Template Sensors

Template 1:	(current consumption in W)

Name:		Bitshake Aktueller Verbrauch	
Entity ID:	sensor.bitshake_aktueller_verbrauch

Template Options:

Template sensor
State template*
1 {{states('sensor.bitshake_smartmeterreader_mt175_power_curr')}}
Unit of measurement	W
Device class		Power
State class		    Measurement
Device			    bitShake SmartMeterReader
Select a device to link to this entity.

Preview:
Bitshake Aktueller Verbrauch	387 W
This template listens for the following state changed events:

Entity: sensor.bitshake_smartmeterreader_mt175_power_curr
Template 2:	(outgoing energy in kWh)

Name:		Bitshake Einspeisung
Entity ID:	sensor.bitshake_einspeisung

Template Options:

Template sensor
State template*
1 {{states('sensor.bitshake_smartmeterreader_mt175_total_out')}}
Unit of measurement	kWh
Device class		Energy
State class		    Total increasing
Device			    bitShake SmartMeterReader
Select a device to link to this entity.

Preview:
Bitshake Einspeisung	24.37 kWh
This template listens for the following state changed events:

Entity: sensor.bitshake_smartmeterreader_mt175_total_out
Template 3:	(incoming energy in kWh)

Name:		Bitshake Verbrauch
Entity ID:	sensor.bitshake_verbrauch

Template Options:

Template sensor
State template*
1 {{states('sensor.bitshake_smartmeterreader_mt175_total_in')}}
Unit of measurement	kWh
Device class		Energy
State class		    Total increasing
Device			    bitShake SmartMeterReader
Select a device to link to this entity.

Preview:
Bitshake Verbrauch	1,508.33 kWh
This template listens for the following state changed events:

Entity: sensor.bitshake_smartmeterreader_mt175_total_in

My Tasmota Smartplug measures the Power from my Solar Panels

Tasmota ENERGY Total
Name:			        Energy Total
Unit of measurement:	kWh
Entity ID:		        sensor.tasmota_energy_total

Here what I selected in the Energy Dashboard:

Grid consumption:
Bitshake Verbrauch

Return to grid:
Bitshake Einspeisung

Solar Panels:
Tasmota ENERGY Total

All of these sensors are showing spikes.

Here my current consumption from Entity ID: sensor.bitshake_aktueller_verbrauch
image

Currently I haven’t got a picture from the other sensors because I deleted the wrong values in Developer Tools - Statistics.
This week I will get my Home Battery System for Solar which I wanted to control with HA, that’s why I’m eager to get finally rid of the spikes.

Many thanks for your help.

kind regards

Option 1: edit your existing filter sensors to change out_of_range to range — the rest of the config looks OK.

Option 2: edit your template sensors to enforce the range. For example:

{{ ([0, states('sensor.bitshake_smartmeterreader_mt175_power_curr')|int(0), 7000]|sort)[1] }}

That makes a list of (min, sensor, max), sorts it, and returns the middle value.

Hello,

I just found time to try your option 1 with exchanging out_of_range with range but it created error messages with yaml config check.

Configuration warnings

Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 20: not a valid value for dictionary value 'filters->1->filter', got 'range' 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 21: 'low' is an invalid option for 'sensor.filter', check: filters->1->low 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 22: 'high' is an invalid option for 'sensor.filter', check: filters->1->high 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 31: not a valid value for dictionary value 'filters->1->filter', got 'range' 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 32: 'low' is an invalid option for 'sensor.filter', check: filters->1->low 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 33: 'high' is an invalid option for 'sensor.filter', check: filters->1->high 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 42: not a valid value for dictionary value 'filters->1->filter', got 'range' 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 43: 'low' is an invalid option for 'sensor.filter', check: filters->1->low 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 44: 'high' is an invalid option for 'sensor.filter', check: filters->1->high 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 53: not a valid value for dictionary value 'filters->1->filter', got 'range' 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 54: 'low' is an invalid option for 'sensor.filter', check: filters->1->low 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 55: 'high' is an invalid option for 'sensor.filter', check: filters->1->high 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 64: not a valid value for dictionary value 'filters->1->filter', got 'range' 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 65: 'low' is an invalid option for 'sensor.filter', check: filters->1->low 
Invalid config for 'filter' from integration 'sensor' at configuration.yaml, line 66: 'high' is an invalid option for 'sensor.filter', check: filters->1->high

I then replaced the “low” and “high” command here…

filter: out_of_range
low: 0
high: 7000

…with “lower_bound” and “upper bound”:

filter: range
lower_bound: 0
upper_bound: 7000

Now I have for the first time no errors or config warnings in the yaml config check.

I’ll report back if It helped or if I still encounter spikes.

Big thanks for the help.

Kind regards

1 Like

Yep, as per the docs. I missed that nuance, sorry. Just another thing that ChatGPT hallucinated to “help” you.