Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
substitutions:
device_name: demo_deepsleep
friendly_name: Demo Deep Sleep
## Board config
esphome:
name: ${device_name}
platform: ESP32
board: m5stack-core-esp32
on_boot:
then:
- light.turn_on: status_led
- script.execute: consider_deep_sleep
## Boilerplate, same for all devices
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
power_save_mode: none
ap:
ssid: Fallback ${device_name}
logger:
api:
password: !secret esphome_secret
ota:
password: !secret esphome_secret
## Hardware
light:
- platform: fastled_clockless
chipset: WS2812B
pin: 27
num_leds: 1
rgb_order: GRB
id: status_led
## Deep Sleep
deep_sleep:
id: deep_sleep_control
sleep_duration: 30s
# Will only pick up a value if this device is configured in Home Assistant > Integrations
# If the device isn't configured, or Home Assistant is offline, it'll default to false
binary_sensor:
- platform: homeassistant
id: prevent_deep_sleep
entity_id: input_boolean.prevent_deep_sleep
script:
- id: consider_deep_sleep
mode: queued
then:
- delay: 10s
- if:
condition:
binary_sensor.is_on: prevent_deep_sleep
then:
- logger.log: 'Skipping sleep, per prevent_deep_sleep'
else:
- deep_sleep.enter: deep_sleep_control
- script.execute: consider_deep_sleep
@alanv72

This comment has been minimized.

Copy link

@alanv72 alanv72 commented Mar 26, 2021

Great info!!! Thanks.. One catch is if you delete a sensor out of HA then it is lost in deepsleep loop forever ;) I setup another binary helper to prevent deep_sleep if not connected and getting HA info...

binary_sensor:

  • platform: homeassistant
    id: prevent_deep_sleep
    entity_id: input_boolean.prevent_deep_sleep
  • platform: homeassistant
    id: ICU
    entity_id: input_boolean.ICU

script:

  • id: consider_deep_sleep
    mode: queued
    then:
    • delay: 30s
    • if:
      condition:
      binary_sensor.is_off: ICU
      then:
      - logger.log: 'Not connected to HomeAssisstant. Please setup in HA to enable deepsleep'
      else:
      - if:
      condition:
      binary_sensor.is_on: prevent_deep_sleep
      then:
      - logger.log: 'Skipping sleep, per prevent_deep_sleep'
      else:
      - logger.log: 'Feeling Sleepy'
      - deep_sleep.enter: deep_sleep_control
    • script.execute: consider_deep_sleep
@lARSHADl

This comment has been minimized.

Copy link

@lARSHADl lARSHADl commented Apr 26, 2021

Can you please share the code for nodemcu esp3266 device i tried to change the board but it doesn't work

https://community.home-assistant.io/t/cant-create-id-to-check-a-toggle-button-for-deep-sleep-in-home-assistant-for-ota-update-on-nodemcu/301545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment