Outdoor Temperature Humidity Sensor with an ESP32 and Esphomeyaml

Any update on your sensor battery life and such? In the US and I’m interested in getting into the hardware. Found this guide was thinking about making one myself.

1 Like

about 3 months.
sadly the ADC sensor isn’t working as expected as described above… dunno how long the batteries will last if they got discharged below a “healthy limit”…

Hi Void, first time posting here in HA forums.

Just to say thank you about your contribution. Things worked great at first shot. This is really amazing.

I didn’t implement sleep mode and battery testing as I’m connecting this device with some cable power supply.

I’m interested anyway about battery life for other projects.

Thanks again,

Michel

Hi Void, can you please tell me the brand and type of this enclosure in the picture?
And maybe where you got it?

:+1: thanks =)

sure.

german ebay just something certified as IP67…

took this one:

any dust/moist proof enclosure will work =)

Do you have a voltage divider? Since ESP32 can only measure 0-3.3V. So a way to solve this is a voltage divder with one 47kohm resistor and one 90kohm. The formula to calulate the battery actual voltage is down below.
Here is some code example to measure 0-5v range.

void loop() {
  //                     Add a voltage divider to the ADC input channel R1 is typically 100K and R2 calculated to achieved 3.3v output as the input to the ADC
  //                     analogRead(ADC pin) / ADC resolution * Voltage Range * Required Value of R2 / Preferred Value of R2
  //                     In this example the input voltage for measurement is 15v
  //                     5v----47K+--to ADC Input GPIO36
  //                                |
  //                               90K
  //                                |
  //                               Gnd
  float voltage = (float)analogRead(36) / 4096 * 5 * 91235 / 90000;
  Serial.print(voltage,1);
  Serial.println("v");
  delay(200);
}

Have you tought about using a voltage divider and a logic level MOSFET to turn off Voltage monitoring when the device is in deepsleep. The Voltage monitoring will drain the battery even when the device is in deepsleep.

Hello, I am using since March a NodeMCU flashed with the luftdaten SW which also writes to influxdb, I use an BME280 which stayed in a special meteo dome but since the weekend it seems the BME is dead, it is giving bogus values.
I am in Germany here humidity is extremely high.
Any ideas what sensor to use outside so it can survive?
I will get it inside and check maybe the soldering is gone but I doubt it.

running 2 BME280s for over 2 years without any problem… only the esp32 is inside a case the sensor itself is not protected at all…

void uses Wemos Lolin 32 board which is a design from 2017. He could either add a voltage divider (maybe even with a mosfet enabled by separate pin) or he could just easily upgrade to Lolin D32 which is an improved design. Including Vbatt being connected to GPIO35 through two 100k resistors.

Here’s the schematic: https://www.wemos.cc/en/latest/_static/files/sch_d32_v1.0.0.pdf

But yeah, adding two 100k resistors is probably even faster.

pretty interesting. since all this discussion here I begin to fell a bit unsecure about my devices. To this point no battery blew up but I feel an urge to change the esps :wink:

on ebay I only find these boards:

So in conclusion, if I swap out the Lolin32s for some new D32s the software shutdown should work right?

Yes. But today I took the Lolin32, soldered two 68k resistors (I ran out of 100k) onto it and voila, battery voltage measurement works with Esphome just as it did with board that have this built in (like in TTGo T-display or TTGO T7). So I’d begin with soldering those two resistors before spending some more money on a new board :slight_smile:

neat!
so for soldering idiots like me: I go pin 34 (or any ADC) --> 100k resistor -> 100k --> + from battery. right?

resistors should be inline or parallel?

This is how the resistors should be soldered/connected:

(I soldered R1’s lead through 35 hole and then R2’s lead to R1’s lead. Get a conical tip for your soldering iron because you want to be neat when soldering Batt+ terminal)

I chose GPIO35 because it’s easier to solder into (the WROOM module chassis!) but GPIO34 is fine as well. The voltage divider means that for full battery (4.2V) the ADC will read out around 2.1V, although there’s stuff about vref fuses, calibration etc. – the best would be to start measuring, use a multimeter to check battery voltage at the same time and fine-tune the multiplication of voltage measured by ADC (“filter” section below). The multiplication factor for me turned out to be around 1.8.

Here’s the relevant part from Esphome config yaml:

sensor:
  - platform: adc
    pin: GPIO35
    attenuation: 11db
    name: "Lolin32 V Battery"
    id: lolin32_vbatt
    update_interval: 60s
    filters:
      - multiply: 1.8
2 Likes

Thanks =)

it works pretty good here on a breadboard. Right now it runs for 8h on a fully charged 18650 and the measurement looks good.

the values flunctuate a bit but I think thats inside an acceptable range. (see the attached image)

log output (adc update interval set to 2 seconds):

esp32_6/sensor/esp32_6_voltage/state 3.95
esp32_6/sensor/esp32_6_voltage/state 3.91
esp32_6/sensor/esp32_6_voltage/state 3.95
esp32_6/sensor/esp32_6_voltage/state 3.91
esp32_6/sensor/esp32_6_voltage/state 3.95

on what voltage should the shutdown be triggered? right now I moved the logic to a HASS automation but I’m uncertain if this should be better stored in the esphome config…

Screenshot_2021-01-27 Übersicht - Home Assistant

I like this collaboration, I’ve used some of your knowledge, you’ve used some of mine :sunglasses:

The values fluctuate a bit because a voltage source (battery) has a voltage drop when there is current drained, batteries are also sensitive to temperature, and esp32’s ADC basically sucks :wink:
From what I read, 3.7 V lithium battery should not be drained below 3.2 V, according to some sources 3.0 V is an absolute minimum (and there’s a minimal amount of energy between 3.2 and 3.0 so it makes no sense to discharge so deeply).

My Lolin32 with a single 18650 cell runs for a third day now with a small voltage drop so far (14 minutes of deep sleep + 30 seconds of running to report BME280 measurements to MQTT broker).

Dang! Thanks again to @Tomash =)
All 3 battery powered esps run now with a voltiage divider and report the correct (+/- 0.02 on repeated readings) voltage of the battery.

I’ve run in a pretty stupid error with incorrect readings on on sensor and learnt my lesson: let HASS manage the shutdown automation (which can be disabled)… The esp will run into an shutdown loop in somehow the ADC reports wrong or no values…

imho the easiest way to do that is to send an “alarm trigger” if the battery drops below a certain value

    on_value_range:
      - below: 3.29
        then:
          - mqtt.publish:
              topic: $devicename/low_voltage
              payload: "true"

for convienient reasons here the updated version of the esphome sketch:
ESP32 + DeepSleep + OTA Awake Switch + ADC report for Battery Voltage

If requested I’ll post the links to the HASS package and lovelace configs.

As always, comments or questions are highly appreciated!

2 Likes

I’ve soldered a 220 uF electrolytic capacitor between 3V3 and GND pins on ESP32, should help with the battery voltage dips due to power usage spikes (which batteries don’t like) while increasing deep sleep current by no more than 10-20 uA. Tests are underway :cowboy_hat_face:

Hello sir, I think if you use Wemos then in deep sleep it draws about 1mA or more, because of voltage converter and USB interface. You could probably lower the deep sleep current 10 or 100 times if you use just ESP32 plain chip, have you tried that? Thanks, Jan