Discover my latest ESP32 experiment with a DHT22 sensor, powered by a 18650 Battery.
Hardware Components
- ESP32 S2 Mini V1.0.0 (find it here)
- DHT22 Humidity / Temperature Sensor (find it here)
- 18650 battery shield V3 (find it here)
esphome:
name: sensore_cucina
friendly_name: Sensore Cucina
esp32:
board: esp32-s2-saola-1
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "[ENCRYPTION_KEY]"
ota:
- platform: esphome
password: "[OTA_PASSWORD]"
wifi:
ssid: "[WIFI_SSID]"
password: "[WIFI_PASSWORD]"
power_save_mode: HIGH # Optimize battery consumption
fast_connect: true # Avoid searching for new Wi-Fi networks
# Enable fallback hotspot (captive portal) in case Wi-Fi connection fails
ap:
ssid: "Sensore Fallback Hotspot"
password: "[HOTSPOT_PASSWORD]"
captive_portal:
# GPIO used to power the DHT22
switch:
- platform: gpio
pin: 5 # Free GPIO to power the DHT22
id: dht22_power
restore_mode: always_off # Starts off
sensor:
- platform: dht
pin: 4 # Data pin of the DHT22
model: DHT22
temperature:
name: "Temperatura Cucina"
humidity:
name: "Umidità Cucina"
accuracy_decimals: 1
update_interval: never
id: dht22_sensor # New ID to avoid conflicts
# Deep sleep activation
deep_sleep:
run_duration: 30s # Time the ESP32 remains on
sleep_duration: 15min # Deep sleep duration
# Turn on the sensor before reading
interval:
- interval: 30s # Same interval as run_duration
then:
- switch.turn_on: dht22_power
- delay: 3s # Wait for the sensor to stabilize
- component.update: dht22_sensor # Use the new ID to update data
- delay: 5s # Wait for the reading
- switch.turn_off: dht22_power