New error- never seen before

" The ESPHome device electric-fence enabled transport encryption or changed the encryption key. Please enter the updated key. You can find it in the ESPHome Dashboard or in your ESPHome device YAML configuration."

I built this device a few years ago and updated the firmware about 6 months ago. There never has been an API or any keys, just a simple ESPHome device. It still works and still compiles, so what is causing this “error”?

If that were the case Home Assistant could only connect to it via MQTT.

Share the device config.

I meant no API key. I have the API component in all of my ESPHome configurations. 63, all but one built by me using an ESP8266-01 or Wemos D1 Mini.

# Sends a 10ms pulse every 800ms to the electric-fence Wemos D1 Mini
#

substitutions:
  device_name: electric-fence
  friendly_name: electric_fence
  my_ssid: iot

packages:
  wifi: !include common/wifi.yaml
  device_base: !include common/esp8266.yaml  
##Overrides:
esp8266:
  board: d1_mini
esphome:
  on_boot:
    then:
      - switch.turn_on: eFence



######################################################
#
# Define the GPIO pins.
switch:
  #D4 (GPIO2, LED_BUILTIN)
  - platform: gpio
    pin:
      number: D4 
      mode: output
    id: builtinLED
    inverted: true

  #D1 (Warning LED on PCB)
  - platform: gpio
    pin:
      number: D1
      mode: output
    id: warningLED

  #D2 (Gate to HV mosfet)
  - platform: gpio
    pin:
      number: D2
      mode: output
    id: hvGate


  - platform: template
    name: ${device_name} LED
    optimistic: yes
    id: eFence
    turn_on_action:
    - while:
        condition:
          lambda: 'return true;'
        then:
        - switch.turn_on: builtinLED
        - switch.turn_on: warningLED
        - switch.turn_on: hvGate
        - delay: 10ms
        - switch.turn_off: builtinLED
        - switch.turn_off: warningLED
        - switch.turn_off: hvGate
        - delay: 400ms
    turn_off_action:
    - switch.turn_off: builtinLED
    - switch.turn_off: warningLED
    - switch.turn_off: hvGate
  

Since I know you’ll ask, here is the esp8266.yaml package file:


substitutions:
  project_name: ${device_name}
  project_version: "1.0"


esphome:
  name: ${project_name}
  friendly_name: ${friendly_name}
  project:
    name: steve.${device_name}
    version: ${project_version}
    
esp8266:
  board: esp01_1m
  framework:
    version: recommended
    
# Enable API for integration with Home Assistant
api:
  # This tells ESPHome to mark the device as offline after 30 seconds of no response
  reboot_timeout: 30s  # Default is 15 minutes.

    
# Enable logging
# Logger level "debug" is needed to get 1-Wire addresses, like the ds18b20.
logger:
  level: DEBUG

I’ve had a the message come up a couple of times. All I had to do was paste the key in again.

As you are not using one I guess just hitting submit without any inputting a key should work.

Nope-
“The encryption key is invalid. Make sure it matches the value in the device’s YAML configuration under api -> encryption -> key.”

I wonder if posting an issue in the black hole of GitHub is called for? But, which one? ESPHome or Home Assistant?

Home Assistant.

This is the closest I could find:

Restarting Home Assistant fixedit.
(Should have tried that first :smile:).

I get that error occasionally as well for devices that don’t use encryption (mostly it seems to occur after the router gets power-cycled). I’ve always just ended up removing it from the ESPHome integration and re-adding. I assume it’s an issue of the IP address changing and the integration not handling that well.

I also occasionally have the same issue but for devices that DO have encryption enabled, but it won’t accept the correct key. Same removal/re-adding always fixes it.

Not a big deal, but also annoying when things don’t ‘just work’.

This issue typically occurs when a different device ends up with the same IP address due to changes in DHCP reservations.

If your devices are running ESPHome 2025.4.x or later and you’ve updated Home Assistant to 2025.5.x (available starting Wednesday, May 7th), the integration should now detect when it’s connected to the wrong device, rather than prompting for an encryption key.

1 Like