How to get the power level of a Wemos D1?

I have a Wemos ESP-Wroom-02 D1 with a built-in battery holder. I successfully flashed a basic ESPHome setup (not sure if the board is supposed to be d1_mini but it works):

esphome:
  name: wemos01
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "XX"
  password: "XX"
  domain: .XX

  ap:
    ssid: "wemos01"
    password: "fallbackap"

captive_portal:

logger:

api:

web_server:

ota:

time:
  - platform: sntp
    servers: 192.168.10.1
    timezone: Europe/Paris

Before going further I would like to monitor the battery level to check if it makes sense to use it standalone (I am pretty sure that not, in which case I would look at using it as a backup).

Is there a way to monitor the battery level of these devices, similarly to what I see in Zigbee sensors?

1 Like

I managed to get the tension of the battery via

sensor:

- platform: adc
  pin: VCC
  name: battery

Is there a relationship between the tension and the battery level?
If so - is there a typical function for Li-ion batteries?

The voltage you are measuring is not the direct battery voltage. Your Battery (if you have an 18650) will range from 4.2 to approx. 2,8V. The board takes that voltage and regulates it to (i think) 3V. If the battery is near empty, this voltage will drop below 3V and therefore you can detect a low voltage scenario. This would be approach 1.

If you would like to get a more precise information on your battery, you could solder the battery + via an voltage devider to the ESP Analog input. (The esp pin will not accept a voltage greater than 3,3V on its analog in).
You will have to measure the battery voltage then and compare it to the voltage the ESP measures. Calculate the factor value by (Battery voltage) / (ESP measurement)

 - platform: adc
    pin: A0
    name: "clever name here"
    update_interval: 30s  
    unit_of_measurement: "%"
    accuracy_decimals: 0
    icon: mdi:battery-medium
    filters:
      - multiply: insert (Battery voltage) / (ESP measurement) here
      - calibrate_polynomial:
         degree: 3
         datapoints:
          - 0.00 -> 0.0
          - 3.00 -> 0.0
          - 3.23 -> 10.0
          - 3.33 -> 20.0
          - 3.40 -> 30.0
          - 3.48 -> 40.0
          - 3.57 -> 50.0
          - 3.65 -> 60.0
          - 3.72 -> 70.0
          - 3.80 -> 80.0
          - 3.88 -> 90.0
          - 4.15 -> 95.0
          - 4.20 -> 100.0
      - lambda: |-
          if (x <= 100) {
            return x;
          } else {
            return 100;
          }

If you manage the electrical part, the above mentioned code will give you a rough estimation on the battery capacity. In my system this has prooven to be sufficiently reliable.

3 Likes