ESPHome device losing connection

Hi there. I’ve been having some issues with a custom made esphome device that I use for my furnace. From time to time, the board seems to lose connection. It started doing so recently and I did not change anything.
When I download the esphome logs it says:

WARNING stufa @ 192.168.1.199: Connection error occurred: Ping response not received after 90.0 seconds
INFO Processing unexpected disconnect from ESPHome API for stufa @ 192.168.1.199
WARNING Disconnected from API
WARNING Can't connect to ESPHome API for stufa @ 192.168.1.199: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.199', port=6053))]: [Errno 113] Connect call failed ('192.168.1.199', 6053) (SocketAPIError)
INFO Trying to connect to stufa @ 192.168.1.199 in the background
INFO Successfully connected to stufa @ 192.168.1.199 in 0.028s
WARNING stufa @ 192.168.1.199: Connection error occurred: stufa @ 192.168.1.199: Connection lost

And in HA it says:

Can't connect to ESPHome API for stufa @ 192.168.1.199: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.199', port=6053))]: [Errno 113] Connect call failed ('192.168.1.199', 6053) (SocketAPIError)

Here is the full esphome config for the device:

esphome:
  name: stufa
  friendly_name: stufa

esp8266:
  board: nodemcu

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "***"

ota:
  - platform: esphome
    password: "***"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Stufa Fallback Hotspot"
    password: "JGwtFfXgiSV2"

captive_portal:

image:
  - file: "images/thermometer.png"
    id: temperature_image
    resize: 35x35
    type: TRANSPARENT_BINARY
  - file: "images/fire-flame.png"
    id: flame_small
    resize: 15x15
    type: TRANSPARENT_BINARY
  - file: "images/fire-flame.png"
    id: flame_big
    resize: 35x35
    type: TRANSPARENT_BINARY
  - file: "images/wifi.png"
    id: wifi_image
    resize: 15x15
    type: TRANSPARENT_BINARY
  - file: "images/no-signal.png"
    id: no_signal
    resize: 15x15
    type: TRANSPARENT_BINARY

switch:
  - platform: gpio
    pin: 
      number: GPIO16
      inverted: true
    name: "Stufa forte/piano"
    id: forte
  - platform: gpio
    pin: GPIO3
    name: "Accensione"
    id: power

one_wire:
  - platform: gpio
    pin: GPIO5
    id: dallastemp

sensor:
  - platform: dallas_temp
    one_wire_id: dallastemp
    address: 0xf403179779378428
    name: "Temperatura"
    id: temperature
    update_interval: 30s
  - platform: homeassistant
    id: set_temperature
    entity_id: climate.stufa_custom
    attribute: temperature
  - platform: rotary_encoder
    name: "Rotary Encoder"
    pin_a: GPIO13
    pin_b: GPIO2
    on_clockwise:
    - homeassistant.service:
          service: climate.set_temperature
          data_template:
            entity_id: climate.stufa_custom
            temperature: !lambda "return id(set_temperature).state - 0.5;"
    on_anticlockwise:
    - homeassistant.service:
          service: climate.set_temperature
          data_template:
            entity_id: climate.stufa_custom
            temperature: !lambda "return id(set_temperature).state + 0.5;"

  
  
font:
  - file: "fonts/ARIAL.TTF"
    id: font1
    size: 10

spi:
  clk_pin: GPIO4
  mosi_pin: GPIO0
binary_sensor:
  - platform: status
    name: "Stufa Status"
    id: status_ha
display:
  - platform: ssd1306_spi
    model: "SSD1306 128x64"
    cs_pin: GPIO14
    dc_pin: GPIO12
    lambda: |-
      it.printf(50, 5, id(font1), "Stufa");
      if(id(status_ha).state==1){
        it.image(85,5,id(wifi_image));
      } else {
        it.image(85,5,id(no_signal));
      }
      it.image(10, 10, id(temperature_image));
      it.printf(50, 25, id(font1), "%.1f°C", id(set_temperature).state);
      if (id(power).state && !id(forte).state) {
        it.image(90,25,id(flame_small));
      }else if (id(power).state && id(forte).state){
        it.image(90,10,id(flame_big));
      } else {
        it.printf(90,25,id(font1),"OFF");
      }
      it.printf(10, 50, id(font1), "Temp. attuale: %.1f°C", id(temperature).state);


Am I missing something?

I advise to set static IP address in wifi and fast connect.

1 Like

Both logs look like they are from HA since they both say they are trying to connect to your esphome device.

It seems your esphome device is possibly not connected to your Wi-Fi network. Have you tried pinging it from another computer to see if it can see it?

I set a static IP but it keeps disconnecting

I think so too, I can see on the screen it (the esphome device) loses connection and then gets it again in a matter of seconds, but this causes the furnace to shut down unexpectedly. I have also thought about it failing, since it’s cheap nodemcu board. Can it be possible?

Entirely a problem that some individual devices cause disconnections. If you buy enough of them even from same place you will find one that is a bit unreliable.
I remember when I first started using ESP32 and 8266 frequent disconnections. Now not so much a problem.

Wi-fi issues are a bugger to debug, largely because there isn’t anything we can see, and many external factors can influence it.

As Neel says, from the Home Assistant console (including the device “Logs” in ESPHome Device Builder) you will only see the information which HA does receive. To see what is happening at the ESP device end you would have to connect to the ESP’s serial (or USB) port … which is rarely convenient.

You can also try checking logs on your Wi-fi router or Access Point, to see if it detected any problem at the same time.

Wi-Fi uses broadcast radio on a small number of frequencies (channels). Like your favorite radio station, every receiver within range picks up the signal - but the software in your device checks the header on every packet and simply ignores all those with a different network name (SSID) or IP Address. This gives the illusion that only your devices are on that wi-fi channel.

Like Citizen Band (CB) radio, if two messages are transmitted at the same time the result is unintelligible, and both need to wait a random time and try again. This works well when the channel is not used so much … but with all your neighbors trying to use the same 13 channels, and broadcasting 4K video (streaming lots of large data packets) there may not be much opportunity for your devices to send their messages.

I use a Wi-fi Analyser app on my android phone, but basically this just tells Signal Strength - not how much the channel is being used.

If the issue is with the wi-fi reception there are some things you can do, but it’s difficult to know which might fix the problem - or for how long.

  • change the channel number(s) that you use for 2.4GHz Wi-Fi
  • move your device and/or Wifi Access Point (WAP) closer together
  • add an additional WAP, creating or expanding a “mesh”

AM or FM? :thinking:

The last part is under your control, but probably requires a hardware change. This is the challenge with custom hardware. You have to design it to fail gracefully. I generally don’t put custom hardware in places where if it fails it will cause a bigger problem. But, at some point if your device loses communication with something (like the temperature sensors) it probably should shut the furnace down.

As far as the connection issue goes, there will be connection issues on at least some devices. I have a few dozen spread around and I can tell that a few of them disconnect and reconnect more than I would like. I have some that are rock solid (no disconnects) for a month or more (since the last power failure). Others have one or two. And then there are the couple of devices that have more than one disconnect a day. The worst one is in the same room as the closest AP and less than a few meters away. I suspect the AP has some issues so I will be replacing it. This is after spending several months getting adequate coverage with enough APs to cover the area I need.

My Tasmota devices log the MQTT and network connections so I have an easy way to tell with them. I only have a few esphome devices so haven’t added that capability for them yet (because the data is usually quite boring).

Ha ha.
I had assumed that people are more likely to know of CB radio than have used UHF radio … but I guess I’m showing my age :wink: