Delay sensor reading on boot

I’ve been doing some experiments with a node deep sleeping and am using an ADC sensor to let me know when it’s time to change the battery. My problem is that there seems to be a voltage sag on wake such that I get an inaccurate voltage report.

I have tried to deal with it by using update_interval, but the sensor automatically updates on boot and then again at the defined interval. The result as a rather displeasing bouncing output:

bounce

Is there a way to suppress the value of the sensor on wake so that I can delay a reading after the sag?

A simple config example of what I’m doing:


esphome:
  name: test-batt

esp32:
  board: tinypico
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: <removed>

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Test-Batt Fallback Hotspot"
    password: <removed>


sensor:
  - platform: adc
    pin: 35
    name: "test batt voltage"
    update_interval: 20s
    attenuation: 11db
    filters:
      - multiply: 3.82


deep_sleep:
  run_duration: 30s
  sleep_duration: 60s

Try this:

sensor:
  - platform: adc
    pin: 35
    name: "test batt voltage"
    update_interval: 1s
    attenuation: 11db
    filters:
      - multiply: 3.82
      - sliding_window_moving_average:
          window_size: 20
          send_every: 20
          send_first_at: 20

This should not send until 20 samples (1 second apart) have been taken. You will still get a slight sag but it will be a 20th of what it was (0.05v rather than 1v).

2 Likes

Thank you so much – this is a really clever solution, @tom_l .

1 Like

I let the new config run for 12 hours and it now works perfectly. A total spread of about 50 millivolts. Amazing.

Thanks again!

2 Likes

I’m also trying this solution.
The battery voltage drops if the load in mA increases. This is normal behaviour (internal impedance of the battery). Therefore I guess using “min” filter would be better than moving_average, because we want to be warned about voltage too low of battery.

My setup runs for 10seconds and then deep sleep for 3 minutes. Need to figure uit the window_size, send_every and send_first in relation to update_interval.