Home Assistant missing readings from ESPHome

I have an ultrasonic sensor in ESPHome that updates every second, with a few filters in place. There are times when it updates immediately in HA, and other times where it doesn’t for 15-20 minutes. Currently I’m looking at values tick by in the ESPHome web portal, but I am not seeing an update to the sensor in HA.

Here’s my sensor config in ESPHome

  - platform: ultrasonic
    trigger_pin: GPIO 5
    echo_pin: GPIO 18
    name: "Car_position"
    update_interval: 1s
    pulse_time: 10us
    timeout: 15m
    filters:
      - filter_out: nan
      - sliding_window_moving_average:
          window_size: 5 #creates a moving average of the last 3 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.7

I believe it should send a reading every second, unless that specific reading is 0.7 different from the moving average of the prior 3 readings. Currently the reading is stable, so I should be seeing regular updates. I understand HA will ignore it when the current and prior reading is the same. But in this case, the sensor is reporting 2.07 (+/- 0.1) repeatedly and the sensor in HA is showing 1.5 or so.

I don’t see any issues in the HA logs.

Anything else I’m missing that could. cause HA to drop readings?

I do wonder if I’m misunderstanding how the sliding window average is working with the delta. I assume if I have a reading get discarded by the delta, it still gets incorporated into the new moving average. But if it doesn’t, obviously I could get stuck at a reading.

The filters are applied in sequence. Means: NaN values are filtered out, a sliding average is calculated and only if the delta of it is more than 0.7 the value is published.

Hah, I started a response and now I see an obvious flaw. Rubber ducking for the win.

I realize in the example I provided, it wouldn’t work. If the value was 1.5, and it changed to 2.07 that’s a delta of 0.57. After three readings, the new moving average would be 2.07 which is within the 0.7 delta and would never get reported.

I have been tweaking these settings, and at some point I think I changed my ranges for ‘garage open’ to a point where this delta is a problem. I’m not sure how it’s been working at all actually.

I think root cause is that the sensor is showing a larger distance than it should for ‘garage open’ state now (1.5 is too much). But I think the answer is that I should change my delta.

Still learning how to best troubleshoot this stuff. For instance, I don’t have a way of knowing which readings are making it through the filter, other than by looking at HA.

Thanks for the help!

Maybe you can work with a negative offset if the distance is always the same value wrong or calibrate with calibrate_linear

Unfortunately in this case they are randomly incorrect values. I’m not sure why they exist, but they are infrequent enough that I’m able to smooth them over with those filters.