Hi everyone!
Recently I got into ESPHome and for a little project I want to set up an ESP32-C6 via Thread to control a couple of connected LEDs via GPIO pin. This generally works very well, even the configuration a MTD with a given poll period.
Since I need to power the device via battery I have to play around with the deep sleep component. Currently I am trying to sleep for 90s and then wait until the API is connected again and some data could be exchanged (10s wait time after connection has been established).
This leads to the following behavior: While the entities (the LED switch and battery voltage metering) keep their value during deep sleep, they switch to “unavailable” as soon as the device wakes up from deep sleep and tries to connect to the network. Also if I toggle the LED switch during deep sleep, the LED does not turn on when the device wakes up again and (theoretically) receives queued thread messages.
This worked flawlessly without the deep sleep component, so some kind of interaction is going on there I assume.
I have read some other topics and the FAQ (which covers the “unavailable” entity problem) but e.g. recreating the device did not help.
Now I hope I can learn some more about the interaction of deep sleep with a minimal thread device and maybe there are some issues in my configuration left. I will try to post some yaml that captures the essence of my setup.
I am using the latest version of ESPHome.
esphome:
name: soldered-sleep
friendly_name: Soldered Sleep
on_boot:
priority: -100 # Run after other components are initialized
then:
- logger.log: "On boot"
- script.execute: enter_deep_sleep_when_ready
esp32:
board: esp32-c6-devkitc-1
framework:
type: esp-idf
openthread:
tlv: <connection string>
device_type: MTD
# here I am not sure if I have to set it that high to communicate
# to the thread network that it takes a while to poll again
poll_period: 120s
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: <key>
# I think ota isn't supported with MTD anyways, maybe I could remove it?
ota:
- platform: esphome
password: <key>
network:
enable_ipv6: true
switch:
- platform: gpio
name: "LED"
pin: GPIO17
id: led
deep_sleep:
sleep_duration: 90s
# I think I need that for the first initial boot, but I'm not sure
# It doesn't seem to hurt
run_duration: 60s
id: deep_sleep_1
# Script to enter deep sleep only after API connection
script:
- id: enter_deep_sleep_when_ready
then:
- deep_sleep.prevent: deep_sleep_1
- wait_until:
api.connected:
- delay: 10s # Give some time for data exchange
# not sure if I need to allow it before entering deep sleep again
- deep_sleep.allow: deep_sleep_1
- deep_sleep.enter: deep_sleep_1
Best regards!
Bjoern