|
| 1 | +Factory Reset |
| 2 | +============= |
| 3 | + |
| 4 | +.. seo:: |
| 5 | + :description: Instructions for setting up conditions that can remotely invalidate all ESPHome preferences stored in flash and reboot ESP. |
| 6 | + |
| 7 | +The ``factory_reset`` component allows you to invalidate (reset) all ESPHome :ref:`preferences <preferences-flash_write_interval>` stored in flash memory and reboot your node. |
| 8 | +After reboot all states, parameters and variables will be reinitialized with their default values. This is useful: |
| 9 | + |
| 10 | +- for devices preflashed with ESPHome to reset behavior back to factory state |
| 11 | +- in case of moving a device to a new environment or starting a new use-case (e.g. reset counters or state) |
| 12 | +- for privacy concerns when giving away a device |
| 13 | + |
| 14 | +.. note:: |
| 15 | + |
| 16 | + **USE WITH GREAT CAUTION!** All credentials, global variables, counters and saved states stored in non-volatile memory will be lost with no chance of recovering them. |
| 17 | + Even raw reading of flash memory with ``esptool`` will not help, since data is physically erased from flash memory. |
| 18 | + |
| 19 | + For devices configured using :doc:`captive portal </components/captive_portal>`, this will reset WiFi settings as well, thus making such devices offline. |
| 20 | + You'll need to be in close proximity to your device to configure it again using a built-in WiFi access point and captive portal. |
| 21 | + |
| 22 | +Reset by Fast Power Cycling |
| 23 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 24 | + |
| 25 | +The ``factory_reset`` component can be configured to clear stored preferences by repeatedly pressing the reset button or power cycling, |
| 26 | +which can be useful to clear the data stored in non-volatile memory on devices that can't be |
| 27 | +connected with a serial cable. The required number of power cycles and the maximum delay between them can be configured in the |
| 28 | +``factory_reset`` component configuration. Points to note: |
| 29 | + |
| 30 | +- The maximum delay affects only the time when the device is powered on, |
| 31 | + not the time when it is powered off (this can't be measured). |
| 32 | +- The reset count will be cleared to zero when any other kind of reset occurs, |
| 33 | + or if the device remains powered on and running for longer than the maximum delay. |
| 34 | +- Not available on RP2040 and RP2350 as the reset cause is not able to be determined. |
| 35 | +- On ESP8266 this feature requires the ``restore_from_flash`` feature to be enabled in the :doc:`ESP8266 platform </components/esp8266>`. |
| 36 | + |
| 37 | +.. code-block:: yaml |
| 38 | +
|
| 39 | + factory_reset: |
| 40 | + resets_required: 5 |
| 41 | + max_delay: 10s |
| 42 | +
|
| 43 | +Configuration variables: |
| 44 | +------------------------ |
| 45 | + |
| 46 | +- **resets_required** (*Optional*, integer): The number of power cycles after which the device will be reset. |
| 47 | + No default, if not configured the power cycle reset feature will be disabled |
| 48 | +- **max_delay** (*Optional*, :ref:`Time <config-time>`): The maximum delay between power cycles. Default: 10s |
| 49 | + |
| 50 | +``on_increment`` Trigger |
| 51 | +^^^^^^^^^^^^^^^^^^^^^^^^ |
| 52 | + |
| 53 | +A trigger is available that will be triggered whenever the current reset cycle count changes. This happens when the |
| 54 | +``factory_reset`` component detects a power cycle, or when the |
| 55 | +cycle count is cleared to zero by timeout or a different type of reset. Arguments passed to the trigger are: |
| 56 | + |
| 57 | +- ``x``: The current cycle count |
| 58 | +- ``target``: The target cycle count |
| 59 | + |
| 60 | +.. code-block:: yaml |
| 61 | +
|
| 62 | + factory_reset: |
| 63 | + resets_required: 5 |
| 64 | + max_delay: 10s |
| 65 | + on_increment: |
| 66 | + - logger.log: |
| 67 | + format: "Fast power cycle count now %u, target %u" |
| 68 | + args: [x, target] |
| 69 | +
|
| 70 | +See Also |
| 71 | +-------- |
| 72 | + |
| 73 | +- :doc:`/components/switch/factory_reset` |
| 74 | +- :doc:`/components/button/factory_reset` |
| 75 | +- :doc:`/components/button/shutdown` |
| 76 | +- :doc:`/components/button/restart` |
| 77 | +- :doc:`/components/button/safe_mode` |
| 78 | +- :apiref:`factory_reset/factory_reset.h` |
| 79 | +- :ghedit:`Edit` |
0 commit comments