Drastic change in sensor value broke sensor

I got a D1 mini with a L298N to control a motor to go both directions. It was successful. Then I tried to add an INA219 to monitor the current going through the motor, in order to detect stalling.

First I set the update_interval of this sensor to be 500ms. From home assistant I can see the normal running current of the motor is about 200ma. And the when I tried to manually stall it, the current changes drastically, which is exactly what I expected. So far so good.

Next I tried to add the following filters to the sensor:

      filters:
        - or:
          - throttle: 10s # only send an update every 10 seconds
          - delta: 0.05 # unless current has changed by more than 0.05a

And that brings a problem, once the current changes drastically, the sensor value returns to 0 and refused to update no matter how long you wait.

Below is the sensor history that illustrate the problem. The left segment is recorded without the filters defined. I tried to stall the motor multiple times, result in multiple spikes. The right segment is recorded with the filters in place. Once the current spiked, it just refused to update it. The motor is still running, but the current value stuck at 0, forever.

What might be the problem? Thanks for helping out.

My yaml

esphome:
  name: d1mini
  friendly_name: d1mini

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "D1Mini Fallback Hotspot"
    password: ""

captive_portal:

# static const uint8_t D0   = 16;
# static const uint8_t D1   = 5;
# static const uint8_t D2   = 4;
# static const uint8_t D3   = 0;
# static const uint8_t D4   = 2;
# static const uint8_t D5   = 14;
# static const uint8_t D6   = 12;
# static const uint8_t D7   = 13;
# static const uint8_t D8   = 15;
# static const uint8_t RX   = 3;
# static const uint8_t TX   = 1;

output:
  - platform: gpio
    id: pin_d8
    pin: GPIO15  # D8
  - platform: gpio
    id: pin_d7
    pin: GPIO13  # D7

# Example configuration entry
i2c:
  - id: bus_a
    sda: GPIO4 # D2
    scl: GPIO5 # D1
    scan: true

sensor:
  - platform: ina219
    i2c_id: bus_a
    address: 0x40
    shunt_resistance: 0.1 ohm
    current:
      name: "INA219 Current"
      id: ina219_current
      filters:
        - or:
          - throttle: 10s # only send an update every 10 seconds
          - delta: 0.05 # unless current has changed by more than 0.05a
    # power:
    #   name: "INA219 Power"
    #   id: ina_power
    max_voltage: 32.0V
    max_current: 3.2A
    update_interval: 500ms

switch:
  - platform: output
    name: "switch1"
    output: pin_d8
    id: switch1
  - platform: output
    name: "switch2"
    output: pin_d7
    id: switch2

cover:
  - platform: template
    name: "Spinner"
    id: Spinner
    optimistic: True
    open_action: 
      - switch.turn_off: switch1
      - switch.turn_on: switch2
      - delay: 30s
      - switch.turn_off: switch2
    close_action: 
      - switch.turn_off: switch2
      - switch.turn_on: switch1
      - delay: 90s
      - switch.turn_off: switch1
    stop_action: 
      - switch.turn_off: switch1
      - switch.turn_off: switch2

Have a look what you get on esphome log.

Isn’t this exactly what the throttle filter does?
The throttle filter docs state this:

throttle

Throttle the incoming values. When this filter gets an incoming value, it checks if the last incoming value is at least specified time period old. If it is not older than the configured value, the value is not passed forward.

So why are you using this throttle filter for your setup?

-or delta: 0.05 should update it anyway. Something doesn’t match here…