ESPHome logo ESPHome
Home / Guides / ESPHome OTA Updates and Security

ESPHome OTA Updates and Security: Passwords, Encryption, Safe Mode and Recovery

How wireless updates work under the hood, how to lock down every device on your network, and how to recover a board when an update goes wrong.

ESPHome Editorial TeamUpdated 2026-11-2412 min read2,129 words
ESPHome over-the-air update progress with password, API key and safe mode checks

After the first USB flash, an ESPHome device spends the rest of its life being updated over Wi-Fi. That convenience depends on two things working well: the over-the-air update mechanism itself, and the security settings that stop anyone else on the network from using it. This guide explains how OTA updates work, how to configure them safely, how to protect the native API and web interface, and how to bring a device back when something goes wrong.

How an OTA update works

ESP32 and ESP8266 chips divide their flash memory into partitions. ESPHome uses a layout with two application slots. The device runs from one slot while an update is written to the other.

When you click Install → Wirelessly, the sequence is:

  1. The Device Builder compiles a new firmware image.
  2. It connects to the device on the OTA port (3232 on ESP32, 8266 on ESP8266 by default) and authenticates with the OTA password.
  3. The image is streamed in chunks and written to the inactive slot.
  4. The device verifies the received image against a checksum sent by the Device Builder.
  5. Only if verification succeeds does the device mark the new slot as the one to boot and restart.

If the connection drops or the checksum fails, the device discards the partial image and keeps running its current firmware. This is why a failed upload almost never leaves a device unusable.

Because the device needs room for two images, flash size matters. A 4 MB chip has ample space. A 1 MB ESP8266 module can only fit two images if each is under roughly 500 KB, which limits which components you can include.

Configuring the OTA component

Since ESPHome 2024.6, OTA is configured as a list of platforms:

ota:
  - platform: esphome
    password: !secret ota_password

The esphome platform is the standard mechanism used by the Device Builder and command-line tool. Other platforms exist for special cases: http_request lets a device download its own firmware from a URL, and web_server allows uploads through the device's built-in web page.

Always set a password. Without one, any computer on your network that can reach the OTA port can replace the firmware. Use a long random string and store it in secrets.yaml.

Changing the OTA password

The device checks incoming updates against the password it currently has, not the one in your new YAML. To change it, the upload that carries the new password must authenticate with the old one. ESPHome handles this when you set the new password and keep the old one available during the transition:

  1. Edit the YAML to the new password.
  2. Install wirelessly. If the upload fails with an authentication error, temporarily set the password back to the old value, install, then change it again.
  3. If you no longer know the old password, install the new firmware over USB instead.

Safe mode

A firmware that compiles cleanly can still misbehave on real hardware: a lambda that crashes, a sensor driver that blocks, a pin conflict that triggers constant resets. If the crash happens before Wi-Fi connects, there is no way to push a fix over the air.

Safe mode protects against this. If a device reboots repeatedly without completing a normal boot, ESPHome starts in a minimal mode with only Wi-Fi, logging and OTA running. In this state you can upload a corrected firmware wirelessly.

safe_mode:
  num_attempts: 10
  reboot_timeout: 5min

The defaults are sensible for most devices. You can also add a button to force safe mode on demand, which is useful during development:

button:
  - platform: safe_mode
    name: "Restart in Safe Mode"

When a device enters safe mode, its log states this clearly at boot, and its normal entities are unavailable until a working firmware is installed.

Securing the native API

The native API lets Home Assistant read every sensor and control every output. Protect it with an encryption key:

api:
  encryption:
    key: !secret office_api_key

Each device should have its own key. The Device Builder generates one automatically for new devices; for older configurations, generate a 32-byte random value encoded in base64. Running openssl rand -base64 32 produces a suitable key.

With encryption enabled, connections without the correct key are rejected, and all traffic between Home Assistant and the device is encrypted and authenticated. The older password: option under api: is deprecated and provides no encryption; remove it from any configuration that still uses it.

Protecting the built-in web server

The web_server component adds a local web page showing the device's entities, logs and, optionally, an OTA upload form. It is handy for standalone devices, but it is also an open door if left unprotected:

web_server:
  port: 80
  version: 3
  auth:
    username: admin
    password: !secret web_password

Firmware uploads through the web page are handled by a separate web_server OTA platform. Leave that platform out of your ota: list unless you specifically need browser uploads, so updates stay with the password-protected esphome platform. If the device is managed through Home Assistant, consider leaving web_server out entirely. It uses flash and RAM, and a device with fewer open services is easier to secure.

The fallback access point and captive portal

When a device cannot connect to your Wi-Fi, the fallback hotspot defined under wifi: ap: lets you reconfigure it from a phone. Treat that hotspot like any other access point:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "Office-Node Fallback"
    password: !secret fallback_password

Without an ap password, anyone within range could join the hotspot when your router is down and change the device's Wi-Fi settings. Set a password of at least eight characters.

Managing secrets properly

Every credential mentioned above belongs in secrets.yaml, referenced with !secret:

  • Wi-Fi network name and password.
  • OTA password.
  • API encryption keys.
  • Fallback hotspot password.
  • Web server credentials.
  • Any API tokens used by http_request or MQTT.

Keep secrets.yaml out of version control by adding it to .gitignore. If you share configurations publicly, double-check that no literal passwords or keys remain in the device files. Rotating a leaked key means installing new firmware on every affected device, so prevention is much easier than cleanup.

Network-level protection

Device settings are one layer. The network is another.

  • Put IoT devices on their own network. A separate VLAN or guest-style SSID for ESPHome and other smart devices limits what a compromised device can reach. Allow Home Assistant to connect to them on ports 6053 (API) and the OTA port, and allow mDNS if you rely on discovery.
  • Block internet access where it is not needed. Most ESPHome devices never need to reach the internet. Exceptions include devices that sync time over SNTP or use http_request.
  • Keep the Device Builder private. It can compile and install firmware to every device. Do not expose port 6052 to the internet; use Home Assistant's authenticated remote access or a VPN instead.

Keeping firmware current

ESPHome releases arrive monthly and include fixes for bugs and occasionally for security issues in components or frameworks. A sustainable routine:

  1. Update the Device Builder.
  2. Read the release notes, especially the breaking changes section.
  3. Validate configurations and update one non-critical device first.
  4. Update the rest, either individually or with Update All.

There is no need to rebuild every device the day a release appears. But devices left on firmware that is years old miss improvements to Wi-Fi stability, memory use and security, so plan to update them every few months.

Recovering a device that will not update

Occasionally a device stops accepting wireless updates. Work through these steps:

Authentication errors

The log shows Error auth result or similar. The OTA password in your YAML does not match the device. Use the old password for one install, or reflash over USB.

Connection refused or timeouts

The device may be in a crash loop, too busy to respond, or on a different network. Check whether it appears online. Power cycle it and try again within the first minute after boot. If it has entered safe mode, the update should now succeed.

Upload starts but fails at a percentage

Weak Wi-Fi is the usual cause. Move the device closer to the access point for the update, or temporarily add power_save_mode: none under wifi.

Not enough space

On small-flash ESP8266 devices, the error mentions insufficient space. Remove large components such as web_server, or perform a two-step update: first install a minimal configuration with only Wi-Fi and OTA, then install the full configuration.

The last resort: USB

If nothing else works, connect the board by USB and flash it with the Device Builder's Plug into this computer option or with ESPHome Web. For devices built into enclosures, plan for this possibility by leaving the serial pins or USB port reachable.

Updating devices from a web server

For devices that are not always reachable from the Device Builder, such as a sensor on a remote outbuilding, the http_request OTA platform lets a device fetch its own firmware:

http_request:

ota:
  - platform: http_request

update:
  - platform: http_request
    name: "Firmware Update"
    source: https://firmware.example.net/outbuilding/manifest.json

The device checks the manifest, compares versions and downloads new firmware when you press the update entity in Home Assistant. Serve these files over HTTPS from a host you control, and protect the files from tampering, since the device will install whatever the manifest points to.

Planning for updates when you design a device

Good update habits begin before the first install. A few design decisions make every later update easier:

  • Choose boards with enough flash. A 4 MB or larger chip leaves room for two images and for components added later. Saving a little on a 1 MB module often costs far more time when updates stop fitting.
  • Keep USB or serial access possible. Even with safe mode, there may be a day when a cable is needed. Leave the USB port reachable, or add a small header for the serial pins on custom enclosures.
  • Place the device where Wi-Fi is strong. OTA transfers of more than a megabyte over a weak link are where uploads most often fail. A Wi-Fi signal sensor quickly shows whether a location is marginal.
  • Keep configurations in version control. If an update introduces a problem, reverting the YAML to the previous commit and reinstalling is the fastest rollback available.

Understanding what an attacker could do

It helps to be specific about the risks, so the effort matches the threat.

An unprotected OTA port lets anyone on the same network replace a device's firmware with their own. That device could then report false sensor values, switch its relays at will, or be used as a foothold to probe other devices. An unencrypted API lets anyone on the network read sensor values and send commands. A fallback hotspot without a password lets someone within radio range reconfigure the device while your router is down.

None of these require advanced skills; they only require network access. That is why the protections in this guide, passwords, encryption keys and network separation, are worth applying to every device, including the simple ones.

Logging and visibility

Security also depends on noticing when something is wrong. Keep a wifi_signal and uptime sensor on every device, and add the version text sensor so Home Assistant always shows which firmware each device runs. An unexpected drop in uptime, a firmware version you did not install or a device that suddenly reports from a different network are signals worth investigating.

Frequently asked questions

Is ESPHome secure enough for door locks and garage doors?

With an encrypted API, an OTA password and a network that limits access, ESPHome is used widely for these devices. Add physical safeguards too, such as limit switches and manual overrides, and keep the firmware current.

What happens if I lose my secrets.yaml file?

Existing devices keep working with the credentials already on them. To update them again, you need the OTA passwords. Without them, each device must be reflashed over USB with a new configuration, after which Home Assistant needs the new API keys. Back up secrets.yaml securely alongside your configurations.

A security checklist for every device

  • An api encryption key unique to the device.
  • An ota password, stored in secrets.yaml.
  • A fallback hotspot password, or no fallback hotspot at all.
  • web_server either removed or protected with authentication, and its OTA platform left out unless needed.
  • No literal credentials in shared or committed YAML.
  • A network that limits what IoT devices can reach.
  • Firmware rebuilt within the last few releases.

Key takeaways

  • OTA updates write to a second flash slot and only switch after verification, so interrupted uploads are safe.
  • Always set an OTA password and a per-device API encryption key.
  • Safe mode lets you fix crashing firmware wirelessly; keep it enabled.
  • Protect or remove the web server and set a password on the fallback hotspot.
  • Keep secrets out of version control, isolate devices on the network and update regularly.