Low battery shutdown recipe

This evening I finally got around to adding over-discharge protection to my LiFeP04 powered sensors. The internet says I’m not the only one with that idea, though I didn’t see anyone else posting a working recipe; here’s what I did. I suppose I could add a missing-data alert to my dashboards to tell me when it’s time to recharge.

NB: LiFePO4 really doesn’t like being deeply discharged; my test cell ran down to 1.5V before the ESP8266 shut off, and now holds 31% of it’s rated capacity. :cry:

edit: adding the runtime check.

Screenshot_2021-03-26_21-47-11

esphome:
  name: widget
  platform: ESP8266
  board: nodemcuv2
  on_boot:
    priority: 260.0
    then:
    - lambda: |-
        float min_batt = 2.75;
        float vcc = ESP.getVcc() / 1024.0;  
        if (vcc < min_batt){
          ESP_LOGE("vbat", "Low Power Supply %.3fV! Sleeping to protect battery", vcc);
          ESP.deepSleep(0);
        } else {
          ESP_LOGI("vbat", "Power Supply OK %.3fV", vcc);
        }

# other stuff goes here: ota, logs, api, network...

sensor:
  - platform: adc
    pin: VCC
    id: vcc_adc
    name: widget vcc
    on_value_range:
      below: 2.75
      then:
        lambda: |-
          ESP_LOGE("vbat", "Low Power Supply %.3fV! Sleeping to protect battery", id(vcc_adc).state);
          ESP.deepSleep(0);

1 Like

my test cell ran down to 1.5V

Auch… Lithium cells die when discharged too far (or charged too far). Yours definitely went “too far” down and it’s gone.
It’s a good idea to protect those cells with protection circuit which disconnects load when cell is empty. many times this circuit is combined with charging circuit on one plate.

Thanks for the code! It will come usefull. I’m just in a phase of configuring my first A/D input on esp2866, but i’ll need external voltag measuring, not Vcc.

Indeed. I thought the cell had integrated protection from over-discharge, but apparently not. My bigger battery packs use smarter BMSes that do protect against over-discharge. Anyway, It was only a small test cell and it motivated me to figure this out, so I call it a net win.