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.
edit: adding the runtime check.
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);