Hi guys,
before I asked you, I have struggled with the documentation, ChatGPT and Gemini to setup a deep sleep for my project. Nothing wa successful, so here I am.
I have the ESP32 WROOM DevKit V1 board.
Powering it with external power supply via micro USB.
Have the RGB LED connected through 3 resistors on all colours to pins 25, 26, 27.
Powering LED by pin 3.3V and GND from the ESP board (on breadboard).
Oled 0,96 inch monochromatic display connected to SCL pin 22 and SDA pin 21.
Powering by pin 3.3V and GND from the ESP board (on breadboard).
DHT11 temperature and humidity sensor connected to pin 18.
Powering by pin 3.3V and GND from the ESP board (on breadboard).
PIR sensor connected to pin 13.
Powering by pin 3.3V and GND from the ESP board (on breadboard).
Microswitch button 1 connected to pin 12 and GND.
Microswitch button 2 connected to pin 19 and GND.
Display is showing me the actual status of energy price (high or low) + temperature of the water in boiler.
RGB led also provides the info if the tariff is high (red) or low (green).
Everything works fine except my deep sleep try.
What I am trying to do is, that:
- if the ESP board boots up, it stays on for 10 seconds, then go to deep sleep.
- if the movement is registered on the PIR sensor, the ESP wakes up for 30 seconds.
- if no movement is detected, after these 30 seconds it goes back to sleep.
I was trying, insted of using the PIR sensor, to use one of the buttons to wake up the device.
But the board does not go to sleep at all.
Here is the code with button I was trying with, but the priority is the PIR sensor to wake up the device.
esphome:
name: esp32
friendly_name: ESP32
esp32:
board: esp32dev
framework:
type: arduino
logger:
level: DEBUG
api:
ota:
- platform: esphome
password: XXXX
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.1.129
gateway: 192.168.1.1
subnet: 255.255.255.0
ap:
ssid: "Esp32 Fallback Hotspot"
password: "YbW321Y0ClyM"
captive_portal:
bluetooth_proxy:
active: true
deep_sleep:
id: deep_sleep_mode
run_duration: 10s # Doba, po kterou bude ESP32 aktivní před vstupem do spánku
sleep_duration: 99999999s # Nulový čas spánku, dokud není tlačítko stisknuto (nenastaví se na čas!)
esp32_ext1_wakeup:
pins:
- 12
mode: ANY_HIGH
light:
- platform: rgb
name: RGB Light
id: rgb_light
red: red
green: green
blue: blue
restore_mode: ALWAYS_OFF
on_turn_on:
then:
- lambda: |-
float brightness = 0.5;
if (id(peak_tariff_value).state == 1) {
id(red).set_level(brightness);
id(green).set_level(0.0);
id(blue).set_level(0.0);
} else {
id(red).set_level(0.0);
id(green).set_level(brightness);
id(blue).set_level(0.0);
}
on_turn_off:
then:
- lambda: |-
id(red).set_level(0.0);
id(green).set_level(0.0);
id(blue).set_level(0.0);
interval:
- interval: 10s
then:
- lambda: |-
float brightness = 0.5;
if (id(peak_tariff_value).state == 1) {
id(red).set_level(brightness);
id(green).set_level(0.0);
id(blue).set_level(0.0);
} else {
id(red).set_level(0.0);
id(green).set_level(brightness);
id(blue).set_level(0.0);
}
output:
- platform: ledc
id: red
pin: GPIO25
- platform: ledc
id: green
pin: GPIO26
- platform: ledc
id: blue
pin: GPIO27
sensor:
- platform: homeassistant
id: peak_tariff_value
entity_id: sensor.peak_tariff_value
name: "Peak Tariff Value"
internal: true
on_value:
then:
- lambda: |-
ESP_LOGD("custom", "Current Peak Tariff Value: %f", id(peak_tariff_value).state);
- platform: dht
pin: GPIO18
model: DHT11
temperature:
name: "Teplota"
id: teplota
humidity:
name: "Vlhkost"
id: vlhkost
update_interval: 60s
- platform: homeassistant
id: teplota_home_assistant
entity_id: sensor.senzor_teploty_bojler_temperature
name: "Bojler"
unit_of_measurement: "°C"
binary_sensor:
- platform: gpio
pin:
number: 19
mode: INPUT_PULLUP
inverted: false
name: "Tlačitko světlo malý pokoj"
device_class: power
on_press:
then:
- switch.toggle: tlacitko_stav
- homeassistant.event:
event: esphome.button_pressed
data:
message: "Světlo malý pokoj bylo stisknuto"
- platform: gpio
pin:
number: 13
mode: INPUT_PULLUP
inverted: True
name: "Tlačítko pro probuzení"
on_press:
then:
- lambda: |-
id(rgb_light).turn_off(); // Vypnutí světla
id(displej).turn_off(); // Vypnutí displeje
- deep_sleep.enter: deep_sleep_mode
switch:
- platform: gpio
id: tlacitko_stav
pin: 33
restore_mode: ALWAYS_OFF
name: "Stav Tlačítka 01"
- platform: gpio
id: tlacitko_stav_02
pin: 32
restore_mode: ALWAYS_OFF
name: "Stav Tlačítka 02"
i2c:
id: bus_i2c
sda: 21
scl: 22
scan: True
frequency: 400kHz
font:
- file: "/config/esphome/arial.ttf"
id: my_font
size: 17
- file: "/config/esphome/arial.ttf"
id: my_font_small
size: 16
display:
- platform: ssd1306_i2c
model: SSD1306 128x64
address: 0x3C
id: displej
lambda: |-
std::string text;
if (id(peak_tariff_value).state == 1) {
text = "VYSOKY TARIF";
} else {
text = "NIZKY TARIF";
}
int text_width = text.length() * 12;
int x = (160 - text_width) / 2;
int y = 10;
it.print(x, y, id(my_font), text.c_str());
char temperature_text[20];
snprintf(temperature_text, sizeof(temperature_text), "Bojler: %.1f °C", id(teplota_home_assistant).state);
int temp_text_width = strlen(temperature_text) * 6;
int temp_x = (120 - temp_text_width) / 2;
int temp_y = 45;
it.print(temp_x, temp_y, id(my_font_small), temperature_text);
Any ideas, what am I doing wrong?