Skip to content

Instantly share code, notes, and snippets.

@boverby
Created July 31, 2020 21:03
Show Gist options
  • Save boverby/26bde9e5f53c645996afc5002d3bca6b to your computer and use it in GitHub Desktop.
Save boverby/26bde9e5f53c645996afc5002d3bca6b to your computer and use it in GitHub Desktop.
working mode on reduced speed esp32 on esphome
### config template for deep sleeping esp32 devices
### This is modelled on lolin32 D32 ( not pro )
# uses gpio pin visible to rtc to wake up on motion
# uses mt3608 step-up dc-dc converter to power rcwl-0916 microwave sensor
# > 11 volts is way more sensitive than 3 or 5 volts for microwave
# using hourly wakeup just to keep up with battery life.
# using 80Mhz clock / high wifi powersave to lower consumption
esphome:
name: d32_1
platform: ESP32
board: lolin_d32
platformio_options:
board_build.f_cpu: 80000000L
on_boot:
priority: 900
then:
lambda: |-
id(wake_up_reason) = esp_sleep_get_wakeup_cause();
id(cpu_speed) = ESP.getCpuFreqMHz() ;
## https://github.com/esphome/feature-requests/issues/547 for wakeup reason
## https://community.home-assistant.io/t/help-with-mqtt-on-message-for-deepsleep-mode/199583
## https://esphome-configs.io/devices/esp32-deep-sleep-bme280/
wifi:
ssid: "USEYOURS"
password: "USEYOURS"
fast_connect: true
power_save_mode: high
manual_ip:
static_ip: 192.168.1.29
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable logging
logger:
level: DEBUG
# drops usage to save battery
# wakeup pin must be rtc pin
# 30 secs every hour unless motion detected
deep_sleep:
run_duration: 30s
sleep_duration: 3570s
wakeup_pin: GPIO13
wakeup_pin_mode: KEEP_AWAKE
id: d32_1_deep_sleep
globals:
- id: cpu_speed
type: int
restore_value: no
initial_value: '0'
- id: wake_up_reason
type: int
restore_value: no
initial_value: '0'
# Enable Home Assistant API
# api:
web_server:
port: 80
mqtt:
broker: '192.168.1.91'
username: ''
password: ''
discovery: true
discovery_retain: true
birth_message:
topic: d32_1/availability
payload: online
will_message:
topic: d32_1/availability
payload: offline
on_message:
- topic: d32_1/ota_mode
then:
- if:
condition:
lambda: 'return x == "ON";'
then:
- logger.log: "prevent deep sleep"
- deep_sleep.prevent: d32_1_deep_sleep
else:
- logger.log: "forcing deep sleep"
- deep_sleep.enter: d32_1_deep_sleep
ota:
switch:
- platform: gpio
pin:
number: GPIO5
inverted: true
name: "d32_1 led"
id: d32_1_led
# motion sensor needs to be on rtc gpio pins to wake up from deep sleep (ext0)
binary_sensor:
- platform: gpio
pin:
number: GPIO13
mode: INPUT_PULLDOWN
name: "d32_1 motion"
device_class: motion
#ESP32 pins GPIO32 through GPIO39 for ADC
sensor:
- platform: adc
pin: GPIO35
attenuation: 11db
name: "d32_1 vbat"
update_interval: 2s
filters:
- multiply: 1.779
- sliding_window_moving_average:
window_size: 2
send_every: 2
accuracy_decimals: 2
- platform: wifi_signal
name: "wifi"
state_topic: d32_1/wifi
update_interval: 60s
- platform: template
name: "d32_1 Wake Reason"
accuracy_decimals: 0
lambda: |-
return (id(wake_up_reason));
# just to prove to myself that the clock has changed
- platform: template
name: "d32_1 cpu speed"
accuracy_decimals: 0
lambda: |-
return (id(cpu_speed));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment