Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensor Filter: Ignore the first values after ESP boot #607

Closed
thEngal opened this issue Feb 21, 2020 · 3 comments
Closed

Sensor Filter: Ignore the first values after ESP boot #607

thEngal opened this issue Feb 21, 2020 · 3 comments

Comments

@thEngal
Copy link

thEngal commented Feb 21, 2020

Describe the problem you have/What new integration you would like
I need a filter that ignores incoming values for a specified time after ESP bootup.

Please describe your use case for this integration and alternatives you've tried:
I want to add a gas sensor (MQ-135) which needs a specified time to heat up. With this filter, the heat up values wouldn’t passed forward to Home Assistant.

Additional context
D342BCE3-A7C3-4B7F-BD54-322D6F2A2B6B

@marklister
Copy link

One could probably accomplish this with a simple lambda filter looking at sensor.uptime...

@CarlosGS
Copy link

CarlosGS commented Aug 8, 2020

I am missing this too ;(

When using sliding_window_moving_average and send_first_at to guarantee a filtered value, the first odd reading (right after rebooting) introduces a distorted sample, which is annoying.
image

A parameter like n_skip: 1 or n_ignore: 1 would be awesome IMHO.

@nkvoll
Copy link

nkvoll commented Oct 9, 2021

I've worked around a similar issue on one of my devices by doing something along these lines to skip the first couple of measurements during boot:

substitutions:
  my_sensor: my_sensor

esphome:
  #...
  on_boot:
    # work around https://github.com/esphome/feature-requests/issues/607
    # set a default value for the skip counter, otherwise it's nan
    - sensor.template.publish:
        id: ${my_sensor}_skips
        state: 0

#...

# register sensors for the datapoints
sensor:
  - platform: my-platform
    name: ${my_sensor}
    filters:
      # work around https://github.com/esphome/feature-requests/issues/607
      # increment a skip counter, this skips the first two measurements 
      - lambda: auto s = id(${my_sensor}_skips); if(s->state > 2) { return x; } else { s->publish_state(s->state+1); return {}; }

  # work around https://github.com/esphome/feature-requests/issues/607
  # create a skip counter
  - platform: template
    id: ${my_sensor}_skips
    internal: true
    accuracy_decimals: 0

It's not very pretty, and a simple skip-filter would be great for this use-case where a sensor's startup values may be off.

@nagyrobi nagyrobi closed this as completed Jul 6, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants