2021-09-20 10:12:46 +02:00
|
|
|
.. _deep_sleep-component:
|
|
|
|
|
2018-05-13 11:37:02 +02:00
|
|
|
Deep Sleep Component
|
|
|
|
====================
|
|
|
|
|
2018-11-14 22:12:27 +01:00
|
|
|
.. seo::
|
|
|
|
:description: Instructions for setting up the deep sleep support for minimizing power consumption on ESPs.
|
2021-11-16 03:19:33 +01:00
|
|
|
:image: hotel.svg
|
2018-11-14 22:12:27 +01:00
|
|
|
|
2018-05-13 11:37:02 +02:00
|
|
|
The ``deep_sleep`` component can be used to automatically enter a deep sleep mode on the
|
|
|
|
ESP8266/ESP32 after a certain amount of time. This is especially useful with nodes that operate
|
|
|
|
on batteries and therefore need to conserve as much energy as possible.
|
|
|
|
|
|
|
|
To use ``deep_sleep`` first specify how long the node should be active, i.e. how long it should
|
2019-05-31 10:18:11 +02:00
|
|
|
check sensor values and report them, using the ``run_duration`` option.
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
Next, tell the node how it should wakeup. On the ESP8266, you can only put the node into deep sleep
|
|
|
|
for a duration using ``sleep_duration``, note that on the ESP8266 ``GPIO16`` must be connected to
|
|
|
|
the ``RST`` pin so that it will wake up again. On the ESP32, you additionally have the option
|
2018-06-05 21:17:58 +02:00
|
|
|
to wake up on any RTC pin (``GPIO0``, ``GPIO2``, ``GPIO4``, ``GPIO12``, ``GPIO13``, ``GPIO14``,
|
|
|
|
``GPIO15``, ``GPIO25``, ``GPIO26``, ``GPIO27``, ``GPIO32``, ``GPIO39``).
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
While in deep sleep mode, the node will not do any work and not respond to any network traffic,
|
|
|
|
even Over The Air updates.
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-05-13 11:37:02 +02:00
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
deep_sleep:
|
|
|
|
run_duration: 10s
|
|
|
|
sleep_duration: 10min
|
|
|
|
|
|
|
|
Configuration variables:
|
2018-08-24 22:44:01 +02:00
|
|
|
------------------------
|
2018-05-13 11:37:02 +02:00
|
|
|
|
2018-06-05 21:17:58 +02:00
|
|
|
- **run_duration** (*Optional*, :ref:`config-time`): The time duration the node should be active, i.e. run code.
|
2021-12-06 23:36:05 +01:00
|
|
|
|
|
|
|
Only on ESP32, instead of time, it is possible to specify run duration according to the wakeup reason from deep-sleep:
|
|
|
|
|
|
|
|
- **default** (**Required**, :ref:`config-time`): default run duration for timer wakeup and any unspecified wakeup reason.
|
|
|
|
- **gpio_wakeup_reason** (*Optional*, :ref:`config-time`): run duration if woken up by GPIO.
|
|
|
|
- **touch_wakeup_reason** (*Optional*, :ref:`config-time`): run duration if woken up by touch.
|
|
|
|
|
2018-06-05 21:17:58 +02:00
|
|
|
- **sleep_duration** (*Optional*, :ref:`config-time`): The time duration to stay in deep sleep mode.
|
2021-09-20 10:12:46 +02:00
|
|
|
- **touch_wakeup** (*Optional*, boolean): Only on ESP32. Use a touch event to wakeup from deep sleep. To be able
|
|
|
|
to wakeup from a touch event, :ref:`esp32-touch-binary-sensor` must be configured properly.
|
2021-02-20 22:02:46 +01:00
|
|
|
- **wakeup_pin** (*Optional*, :ref:`Pin Schema <config-pin_schema>`): Only on ESP32. A pin to wake up to once
|
|
|
|
in deep sleep mode. Use the inverted property to wake up to LOW signals.
|
2018-06-05 21:17:58 +02:00
|
|
|
- **wakeup_pin_mode** (*Optional*): Only on ESP32. Specify how to handle waking up from a ``wakeup_pin`` if
|
|
|
|
the wakeup pin is already in the state with which it would wake up when attempting to enter deep sleep.
|
|
|
|
See :ref:`deep_sleep-esp32_wakeup_pin_mode`. Defaults to ``IGNORE``
|
|
|
|
- **id** (*Optional*, :ref:`config-id`): Manually specify the ID used for code generation.
|
|
|
|
|
2018-11-13 14:07:18 +01:00
|
|
|
Advanced features:
|
|
|
|
|
|
|
|
- **esp32_ext1_wakeup** (*Optional*): Use the EXT1 wakeup source of the ESP32 to wake from deep sleep to
|
|
|
|
wake up on multiple pins. This cannot be used together with wakeup pin.
|
|
|
|
|
|
|
|
- **pins** (**Required**, list of pin numbers): The pins to wake up on.
|
|
|
|
- **mode** (*Optional*): The mode to use for the wakeup source. Must be one of ``ALL_LOW`` (wake up when
|
|
|
|
all pins go LOW) or ``ANY_HIGH`` (wake up when any pin goes HIGH).
|
|
|
|
|
2019-10-13 12:57:13 +02:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
Only one deep sleep component may be configured.
|
|
|
|
|
2018-06-05 21:17:58 +02:00
|
|
|
.. _deep_sleep-esp32_wakeup_pin_mode:
|
|
|
|
|
|
|
|
ESP32 Wakeup Pin Mode
|
2018-08-24 22:44:01 +02:00
|
|
|
---------------------
|
2018-06-05 21:17:58 +02:00
|
|
|
|
|
|
|
On the ESP32, you have the option of waking up on any RTC pin. However, there's one scenario that you need
|
2019-02-16 23:25:23 +01:00
|
|
|
to tell ESPHome how to handle: What if the wakeup pin is already in the state with which it would wake up
|
2018-06-05 21:17:58 +02:00
|
|
|
when the deep sleep should start? There are three ways of handling this using the ``wakeup_pin_mode`` option:
|
|
|
|
|
|
|
|
- ``IGNORE`` (Default): Ignore the fact that we will immediately exit the deep sleep mode because the wakeup
|
|
|
|
pin is already active.
|
|
|
|
- ``KEEP_AWAKE``: Keep the ESP32 awake while the wakeup pin is still active. Or in other words: defer the
|
|
|
|
activation of the deep sleep until the wakeup pin is no longer active.
|
|
|
|
- ``INVERT_WAKEUP``: When deep sleep was set up to wake up on a HIGH signal, but the wakeup pin is already HIGH,
|
|
|
|
then re-configure deep sleep to wake up on a LOW signal and vice versa. Useful in situations when you want to
|
|
|
|
use observe the state changes of a pin using deep sleep and the ON/OFF values last longer.
|
2018-06-01 18:10:00 +02:00
|
|
|
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
.. _deep_sleep-enter_action:
|
|
|
|
|
|
|
|
``deep_sleep.enter`` Action
|
2018-08-24 22:44:01 +02:00
|
|
|
---------------------------
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
This action makes the given deep sleep component enter deep sleep immediately.
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
on_...:
|
|
|
|
then:
|
2021-05-10 08:59:48 +02:00
|
|
|
- deep_sleep.enter:
|
|
|
|
id: deep_sleep_1
|
|
|
|
sleep_duration: 20min
|
2021-02-15 18:32:07 +01:00
|
|
|
|
|
|
|
Configuration options:
|
|
|
|
|
2021-05-11 17:36:03 +02:00
|
|
|
- **sleep_duration** (*Optional*, :ref:`templatable <config-templatable>`, :ref:`config-time`): The time duration to stay in deep sleep mode.
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
.. _deep_sleep-prevent_action:
|
|
|
|
|
|
|
|
``deep_sleep.prevent`` Action
|
2018-08-24 22:44:01 +02:00
|
|
|
-----------------------------
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
This action prevents the given deep sleep component from entering deep sleep.
|
2021-02-14 16:07:40 +01:00
|
|
|
Useful for keeping the ESP active during data transfer or OTA updating (See note below for more information).
|
2018-08-22 22:05:28 +02:00
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
on_...:
|
|
|
|
then:
|
|
|
|
- deep_sleep.prevent: deep_sleep_1
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
For example, if you want to upload a binary via OTA with deep sleep mode it can be difficult to
|
|
|
|
catch the ESP being active.
|
|
|
|
|
|
|
|
You can use this automation to automatically prevent deep sleep when a MQTT message on the topic
|
2018-11-10 14:31:27 +01:00
|
|
|
``livingroom/ota_mode`` is received. Then, to do the OTA update, just
|
2019-07-11 10:20:04 +02:00
|
|
|
use a MQTT client to publish a retained MQTT message described below. When the node wakes up again
|
2018-08-22 22:05:28 +02:00
|
|
|
it will no longer enter deep sleep mode and you can upload your OTA update.
|
|
|
|
|
|
|
|
Remember to turn "OTA mode" off again after the OTA update by sending a MQTT message with the payload
|
2021-02-20 22:02:46 +01:00
|
|
|
``OFF``. To enter the the deep sleep again after the OTA update send a message on the topic ``livingroom/sleep_mode``
|
2020-12-21 01:55:44 +01:00
|
|
|
with payload ``ON``. Deep sleep will start immediately. Don't forget to delete the payload before the node
|
|
|
|
wakes up again.
|
2018-08-22 22:05:28 +02:00
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
deep_sleep:
|
|
|
|
# ...
|
|
|
|
id: deep_sleep_1
|
|
|
|
mqtt:
|
|
|
|
# ...
|
|
|
|
on_message:
|
2020-12-21 01:55:44 +01:00
|
|
|
- topic: livingroom/ota_mode
|
|
|
|
payload: 'ON'
|
|
|
|
then:
|
|
|
|
- deep_sleep.prevent: deep_sleep_1
|
|
|
|
- topic: livingroom/sleep_mode
|
|
|
|
payload: 'ON'
|
|
|
|
then:
|
|
|
|
- deep_sleep.enter: deep_sleep_1
|
2018-08-22 22:05:28 +02:00
|
|
|
|
2018-06-01 18:10:00 +02:00
|
|
|
See Also
|
2018-08-24 22:44:01 +02:00
|
|
|
--------
|
2018-06-01 18:10:00 +02:00
|
|
|
|
|
|
|
- :doc:`switch/shutdown`
|
|
|
|
- :ref:`automation`
|
2019-05-12 22:44:59 +02:00
|
|
|
- :apiref:`deep_sleep/deep_sleep_component.h`
|
2019-02-07 13:54:45 +01:00
|
|
|
- :ghedit:`Edit`
|