Potential API issues

Hi have been working on a Shelly 1L to move it over ESPHOME and this morning made a change where i lost the orignal API encryption key so I reflashed it but since then I’ve been having some issues with the unit. I am getting the following errors in my log file:

[13:20:52][D][api.connection:917]: Home Assistant 2022.11.5 (192.168.86.12): Connected successfully
[13:20:52][D][time:044]: Synchronized time: 2022-12-05 13:20:52
INFO shelly-1l-entrance.local: Error while reading incoming messages: Error while reading data: [Errno 104] Connection reset by peer
INFO shelly-1l-entrance.local: Ping Failed: Error while reading data: [Errno 104] Connection reset by peer
INFO Disconnected from ESPHome API for shelly-1l-entrance.local
WARNING Disconnected from API
INFO Successfully connected to shelly-1l-entrance.local
[13:21:11][D][api:102]: Accepted 192.168.86.12
[13:21:11][D][api.connection:917]: Home Assistant 2022.11.5 (192.168.86.12): Connected successfully
[13:21:11][D][time:044]: Synchronized time: 2022-12-05 13:21:11

The code I have pulled together is as so:

substitutions:
  device_name: "Shelly 1L Entrance"
  max_temp: "70.0"

# Basic Config
esphome:
  name: shelly-1l-entrance
  platform: ESP8266
  board: esp01_1m

# Enable Home Assistant API
api:
  encryption:
    key: "vIOjotBAPBL5TgbSBCpDqu5275mfn/nj2GNF9ULr/l4="

ota:
  password: "21072244fb893e9dcdd4868be4fcbdac"

wifi:
  ssid: !secret wifi_ssid_foundation
  password: !secret wifi_password_foundation
  power_save_mode: HIGH # for ESP8266 LOW/HIGH are mixed up, esphome/issues/issues/1532
  ap:
    ssid: "${device_name} Fallback"
    password: !secret fallback_password

captive_portal:
  
logger:
  level: DEBUG

# Enable Web server (optional).
web_server:
  port: 80

# Sync time with Home Assistant.
time:
  - platform: homeassistant
    id: homeassistant_time

# Text sensors with general information.
text_sensor:
  - platform: wifi_info
    ip_address:
      name: "${device_name} IP"

# Sensors with general information.
sensor:
  # Uptime sensor.
  - platform: uptime
    name: ${device_name} Uptime

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: "${device_name} WiFi Signal"
    update_interval: 60s

  - platform: ntc
    sensor: temp_resistance_reading
    name: "${device_name} Temperature"
    unit_of_measurement: "°C"
    accuracy_decimals: 1
    device_class: temperature
    calibration:
      b_constant: 3350
      reference_resistance: 10kOhm
      reference_temperature: 298.15K
    on_value_range:
      - above: ${max_temp}
        then:
          - homeassistant.event:
              event: esphome.overheat
              data:
                title: "${device_name} has overheated."
  - platform: resistance
    id: temp_resistance_reading
    sensor: temp_analog_reading
    configuration: DOWNSTREAM
    resistor: 32kOhm
  - platform: adc
    id: temp_analog_reading
    pin: A0

switch:
- platform: gpio
  pin: GPIO5
  id: shelly_relay
  name: "${device_name} Relay"
  # after reboot, keep the relay off. this prevents light turning on after a power outage
  restore_mode: ALWAYS_OFF

binary_sensor:
  - platform: gpio
    name: "${device_name} Input"
    pin:
      number: GPIO4
    # small delay to prevent debouncing
    filters:
      - delayed_on_off: 50ms
    # config for state change of input button
    on_state:
        then:
          - if:
              condition:
                and:
                  - wifi.connected:
                  - api.connected:
                  - switch.is_on: shelly_relay
              # toggle smart light if wifi and api are connected and relay is on
              then:
                - homeassistant.service:
                    service: light.toggle
                    data:
                      entity_id: light.nue_downlight_entrance_light
              # else, toggle relay
              else:
                - switch.toggle: shelly_relay
    id: button

If I hit the relay switch in the controls section of the device it just flicks back on and the same goes for the actions in the ESP web page, it just dosent seem to be happy.

Just a guess because I don’t use encryption with my api: keyword. Try removing encryption: and key:

Thanks for the suggestion, I had a go at that but I’m getting the following errors in the log file now:

INFO shelly-1l-entrance.local: Error while reading incoming messages: Error while reading data: [Errno 104] Connection reset by peer
INFO shelly-1l-entrance.local: Ping Failed: Error while reading data: [Errno 104] Connection reset by peer
INFO Disconnected from ESPHome API for shelly-1l-entrance.local
WARNING Disconnected from API
INFO Successfully connected to shelly-1l-entrance.local
[13:59:31][D][api:102]: Accepted 192.168.86.12
[13:59:31][W][api.connection:085]: 192.168.86.12: Reading failed: BAD_INDICATOR errno=11
[13:59:31][D][api:102]: Accepted 192.168.86.12
[13:59:31][W][api.connection:085]: 192.168.86.12: Reading failed: BAD_INDICATOR errno=11
[13:59:32][D][api:102]: Accepted 192.168.86.12
[13:59:32][W][api.connection:085]: 192.168.86.12: Reading failed: BAD_INDICATOR errno=11
[13:59:33][D][api:102]: Accepted 192.168.86.12
[13:59:33][W][api.connection:085]: 192.168.86.12: Reading failed: BAD_INDICATOR errno=11

Delete the device from Home Assistant. Restart Home assistant (probably not required but do it to cover all bases).

Re-flash the device with the new encryption key.

Re-add the device to Home Assistant.

Store the encryption key in a password manager.

Thanks both for your help. So I have managed to fix the issue. as suggested the steps were:

  • Delete from HA
  • Remove the encryption from the config file and reflash
  • Readd to HA

No need to restart HA