All ESPHome devices random unavailable

I use sonoff devices with ESPHome, all the devices comes unavailable at rondom times. and mostly all together. At the same time. After that I have an haunted house. With lights switching on. Is there a way to prevent this?

The wifi sensor gives a solid connection.
This is my template.

#Sonoff Mini
#Pin 	Function
#GPIO0 	Button (inverted)
#GPIO4 	SW Input (S2)
#GPIO12 	Relay and Red LED
#GPIO13 	Blue LED (inverted)
#GPIO16 	Optional sensor
substitutions:
  project_name: 'schakelaarbadkamerbeneden'
  friendly_name: 'schakelaar_badkamer_beneden'
  SSID_password: 'xxxxxx'
  SSID_name: 'xxxxxx' 

#  switch_icon: '' #mdi:ICON https://materialdesignicons.com/

esphome:
  name: ${project_name}
  platform: ESP8266
  board: esp8285

wifi:
  ssid: ${SSID_name}
  password: ${SSID_password}

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${friendly_name} FB
    password: ${SSID_password}

#captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "xxxxxx"

binary_sensor:
  - platform: gpio
    id: button
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: True
    filters:
      - delayed_on: 50ms
      - delayed_off: 50ms
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_single"
      - timing:
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_double"
      - timing:
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at most 399ms
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_triple"
      - timing:
          - ON for at least 2s
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_long"

sensor:
  - platform: wifi_signal
    id: wifi2
    update_interval: 60s

  - platform: template
    name: ${friendly_name} - Wifi signal
    unit_of_measurement: '%'
    accuracy_decimals: 0
    icon: "mdi:wifi"
    lambda: |-
        if (id(wifi2).state < -92.0)
          return 100.0;
        if (id(wifi2).state > -21.0)
          return 1.0;
        else
          return round(( -0.0154 * id(wifi2).state * id(wifi2).state ) - ( 0.3794 * id(wifi2).state ) + 98.182 );

text_sensor:
  - platform: template
    name: ${friendly_name} - Switches
    id: buttons
    icon: "mdi:light-switch"

1 Like

How solid, dBm?

What hardware is your wireless network running on?

How many clients do you have?

The wifi sugnal update sensor is 60sā€¦ in between a lot of bad things can happenā€¦

Do you only experience wifi issues with esphome?

At night around 11 clients, and the logs show around ā€œ-67db, -60db, -58dbā€ The network is running on two wifi accespoint (wifi 6 enabled) with an edimax router.

Iā€™am using a pushbutton switch for single, double, triple and long press. If home-assistant report unavailable ESPhome / home assistant resend the last status and it triggers the automation, is it not possible to configure esphome or homeassistent to ignore the status after status ā€œunavailableā€

alias: Gang boven licht aan
description: ''
trigger:
  - entity_id: sensor.schakelaar_boven_gang_switches
    platform: state
    to: button_single
condition: []
action:
  - entity_id: light.0x14b457fffe2623f5_light
    service: light.toggle
mode: single

Sorry, I meant to ask: do you experience other wifi issues or only with espā€™s? And maybe for time being update the frequency for the

You should set static IP addresses on your nodes:

Make sure you set addresses that are outside the routerā€™s DHCP range or reserved within it. Try just setting it on one or two devices at first ā€” Iā€™ll bet they stay up when the rest go offlineā€¦

2 Likes

@sender only the esp, and approximately one time a day. I will shorten the update_interval and see whatā€™s happen.

If esp canā€™t connect via api from homeassistant the same behaviour can be seen. I meant to say, donā€™t stare blind on the wifi part onlyā€¦

@sender If ESPs cant connect intermittently it is very likely to be a wifi issue.

I think Troonā€™s advice is the best thing to try.

Iā€™ve got more ESPHome devices than I can be bothered counting and they all stay connected, 100%. Unless they are Kogan V1 smart power monitoring sockets. Those bastards die about one hour after their warranty expires.

Mind you I have 4 wifi access points arround my house broadcasting different SSIDs and each ESP is programmed to connect to the nearest SSID. And each ESP has a static IP address.

Agreed, thatā€™s why I asked if there are other issues with wifi. And advised to up the frequency for wifi signal scanner.

I once had a wifi ap via poe, giving me huge headaches (did not know this was the culprit a that time)ā€¦ turned out the cable was good enough for poe but not the ehternet signal. Max speed was 100Mbps and bot 1Gbps. Replaced the cable and since rock solid. So hence my suggestion not to stare blind on wifi. A cable or network error to and from homeassistant can also give a totally wrong picture of these kind of problems.

Yeah. Ok.

OP did say it was all of the clients.

I set all the devices to a static IP. But I do not rule out that it is a docker / homeassistant issue. I will see what happens tonight.

Static ip is not the solution for me, still sometimes homeassistant report ā€˜unavailableā€™. Tonight Iā€™m using a different approach. After the use from the pushbutton, I add a new state ā€œbutton_restā€ So if homeassistant reports ā€˜unavailableā€™ it will return with the status ā€œbutton_restā€. And there is no automation on ā€˜button_restā€™. So hopefully this will resolve my haunted house problem. Fingers crossed.

    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 400ms
        then:
          - text_sensor.template.publish:
              id: buttons
              state: "button_pressed"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_single"
          - delay: 50ms
          - text_sensor.template.publish:
              id: buttons
              state: "button_rest"

Iā€™m pretty sure you can by adding from:

trigger:
  - entity_id: sensor.schakelaar_boven_gang_switches
    platform: state
    from: ### enter default state here.
    to: button_single

You may need to list the other states as the amount of presses increases

    from:
      - ### state_1
      - ### state_2
trigger:
  - entity_id: sensor.schakelaar_boven_gang_switches
    platform: state
    from: button_pressed
    to: button_single

Good idea, that will also work, so two different solutions for my problem. Thanks for solutions.

Itā€™s a workaround rather than a solution, but this may help:

One of my ESPHome units (a Wemos D1 Mini with OLED screen) used to drop its connection to HA but maintain its network connection, which was annoying as this is the temperature sensor for my central heating system.

The ESPHome API reboot_timeout didnā€™t work, but I found that forcing it off the wifi triggered the wifi reboot_timeout. As I can control this from HA with my Unifi gear, I threw this automation together to force a reboot if it dropped offline (where switch.hall_temperature_sensor is created by the Unifi integration and blocks it from the wifi when off):

- alias: Climate - fix hall sensor becoming unavailable

  description: >-
    Hall temperature sensor is an ESP unit that can drop off the API
    occasionally. If it does this, this automation tries to kick it
    back into life by disconnecting it from the wifi for 5 mins.
    We also turn off the central heating as a safety precaution.

  id: 78d4a304-1723-4676-8bf5-d8baa5ee4700

  trigger:
    - platform: state
      entity_id: sensor.hall_temperature
      to: 'unavailable'
      for:
        seconds: 30

  action:
    - service: notify.admin
      data_template:
        message: 'Hall temperature sensor offline! Trying to reconnect...'
    - service: switch.turn_off
      entity_id: switch.hall_temperature_sensor
    - service: switch.turn_off
      entity_id: switch.chc_central_heating_relay
    - delay: 300
    - service: switch.turn_on
      entity_id: switch.hall_temperature_sensor
    - service: notify.admin
      data_template:
        message: 'Done. If still offline, please solve manually.'

A subsequent update to the ESPHome OLED driver has fixed my problem now.

1 Like

Are these using the same SSID??
If so, it might be the are jumping between the 2 ?

Shouldnā€™t be. I have several ESPHome devices (mostly D1 Mini, couple of flashes Shellys) that can see two of my three APs, all of which are running the same four SSIDs (home + guest on 2.4 and 5GHz). They choose one at bootup and donā€™t roam unless one of the APs goes down.

Hereā€™s the relevant section of code that I use on all my devices:

esphome:
  name: utility_motion
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "xxx"
  password: "xxx"
  manual_ip:
    static_ip: 192.168.1.38
    gateway: 192.168.1.1
    subnet: 255.255.255.0

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxx"

ota:
  password: "xxx"

I have the same problem with one of my Esphome device which is Sonoff T1 3relays UK.
I have it configured with two Thermostat Climate Controller components controlling the two relays plus the third relay is alway on.
What is happening when all the three relays are turned on the ESPhome looses connection to HomeAssistant but the WiFi connection on the ESPhome is still up as reported by the Access point, as soon I turn off one of the relays the connection to HomeAssistant resumes. WiFi signal is -42 dB so reception is not a problem.
As you can see I can easily replicate the issue by turning on all 3 relays.
Have tried static IP, have tried to remove status light component as suggested and as well WiFi sleep setting have been configured as advised on the ESPhome FAQ.