Hello, I have been struggling for the past day to understand how to make sensors work in combination with deep sleep.
I have two sensors connected to my ESP32 - DHT11 for humidity and BMP280 for temperature and pressure. My goal is to keep the ESP awake for enough time to read and report the values from both sensors and go to sleep after that.
I noticed that especially DHT11 is very inconsistent with reporting values. Based on the logs, it takes from 3s up to 50s between BMP280 and DHT11 reading. So the run_time should be set to at least 1 minute in order to get the readings, but my goal is to enter deep sleep automatically as soon as all the sensors are done sending their data.
My guess is the wanted behavior could be achieved by setting up automation in combination with some scripts. Maybe it could be done with on_value automation on sensor?
Since I have very little experience with ESPHome and setting up automations, I would really appreciate any help on this topic. Has anyone managed to achieve something similar?
Thank you!
The following is my current config:
esphome:
name: "esp32-inside"
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: !secret ap_ssid
password: !secret ap_password
captive_portal:
i2c:
sda: 21
scl: 22
scan: true
id: bus_a
sensor:
- platform: dht
model: DHT11
pin: 15
humidity:
name: "Humidity DHT"
update_interval: 60s
- platform: bmp280
temperature:
name: "Temperature BMP"
oversampling: 16x
filters:
- offset: -2.3
pressure:
name: "Pressure BMP"
address: 0x76
update_interval: 60s
# Update interval has no effect when deep sleep is in use and it is longer than run_duration. Esphome always sends the readings on boot.
deep_sleep:
id: deep_sleep_1
run_duration: 60s
sleep_duration: 60s
mqtt:
broker: !secret mqtt_broker
port: 1883
username: !secret mqtt_username
password: !secret mqtt_password
on_message:
- topic: esp32-inside/ota_mode
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_1
- logger.log: "OTA mode enabled - deep sleep mode disabled"
- topic: esp32-inside/sleep_mode
payload: 'ON'
then:
- deep_sleep.enter: deep_sleep_1
- logger.log: "deep sleep mode enabled"