Why does an ESP32 disconnected from power still appear as `ONLINE` in HA ESPHome?

Hello!

I flashed an ESP32 and adopted it in HA ESPHome:

substitutions:
  name: "esp32-test"
  friendly_name: "ESP32 Test"

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: true
  project:
    name: 7wells.test
    version: 1.0.0

esp32:
  board: az-delivery-devkit-v4
  framework:
    type: arduino
    version: recommended

logger:
  level: DEBUG

api:

ota:
  - platform: esphome

wifi:
  ssid: !secret router_ssid
  password: !secret router_password
  manual_ip:
    static_ip: 192.168.11.3
    gateway: 192.168.11.1
    subnet: 255.255.255.0
    dns1: 192.168.11.1
    dns2: 192.168.11.1
  ap:
    ap_timeout: 1min
    ssid: ${friendly_name}
    password: !secret esp32_test_ap_password
    manual_ip:
      static_ip: 192.168.11.3
      gateway: 192.168.11.1
      subnet: 255.255.255.0
      dns1: 192.168.11.1
      dns2: 192.168.11.1

captive_portal:

improv_serial:

esp32_improv:
  authorizer: none

web_server:
  port: 80
  local: true
  version: 2
  include_internal: true
  ota: off
  auth:
    username: !secret web_username
    password: !secret web_password

It puzzles me that it still appears as ONLINE despite I disconnected the ESP32 from power, also after HA restart. Is this a known issue? What might I be missing? There is nothing in HA’s protocol.

Thanks for pointing me into the right direction! :+1:

Kind regards
7wells

Most devices do not have a hardware feature that allow them to send a notification to the network that they are being disconnected, so devices are still considered online by the network.
Some systems have a timeout for when a device have not been seen for a period, then it is marked as offline/unavailable. The problem is that battery powered devices might only be online with great intervals, like many hours or even days, and so the timeout can not be lower than the device with the longest interval.

In your case with ESPHome it is the same, but if you restart the ESPHome addon, then it should reset the state.
My guess is that you restarted the HA core container, which will leave the ESPHome container running.
Either restart the ESPHome addon or the entire HA host.

1 Like

Thank you so much for your very understandable explanation and offered solution! :heart: I restarted the ESPHome addon, and now the status is correctly shown. :+1:

If I may add this:
I assume that there is no “automation” (I mean by HA automations or other means) that could take care about it, as restarting the ESPHome addon on a regular basis (just to show the correct on/offline status of nodes) would come along with unwanted side effects. Correct?

I do not think there is so many bad effects from restarting the ESPHome addon.
It is mainly used to push new firmware and not for the day-to-day operation in relation to HA.

I think there is a service call to restart addons, but I do not know for sure and I am unable to check for it the next couple of days, so maybe somebody else can answer that.

1 Like

Another option is described in the ESPHome documentation - and I should have observed this earlier:

Option: status_use_ping

By default the dashboard uses mDNS to check if nodes are online. This does not work across subnets unless your router supports mDNS forwarding or avahi.

Setting this to true will make ESPHome use ICMP ping requests to get the node status. Use this if all nodes always have offline status even when they’re connected.

I am not sure if I do have different subnets in this regard.

My second router, my Raspberry Pi 4 connected to it via ethernet (and runs Home Assistant), as well as the ESP32 devices (all with static IPs) are on the same subnet (192.168.11.x).

My primary router is on a different subnet (192.168.178.x) and is usually the gateway and DNS for everything.

Both routers are connected together via WiFi and WireGuard tunnel.

If this matters here, I am not sure. I play around with the status_use_ping parameter (i.e. set it to true), but still sometimes, ESP32 devices appear offline despite they are online.

And just now I have 2 ESP32 devices added, they appear under the ESPHome integration, and I can see that their entities all show up ok.

However, the ESPHome Add-on (shown via the side panel) is still empty, i.e. the 2 added ESP32 devices do not show up there. Restarting the ESP32 Add-on has not helped, deinstalling and reinstalling it has not helped either, and restarting the whole Raspberry Pi has also not helped at all.

The protocol of the ESP32 Add-on does not show any errors, nor does the HA system protocol after the device restart.

How do I get the EP32 devices - which seem to work alright - into the ESPHome panel?

I am a bit lost. :thinking:

The ESPHome addon only list the devices it has yaml code for, I think.
The ESPHome addon is for upgrading the firmware based on the yaml code.
The ESPHome integration is for controlling the ESPHome devices and if you need to add a new device to the integration, then just do as you would for adding the integration in the first place.

1 Like

I flashed an ESP32 with YAML code via the Python esphome tool on a Win 11 PC and connected it to WiFi. It did not show up in ESPHome of HA. Only after I saved the same YAML code via HA File Editor in the /homeassistant/esphome/ folder, the node appeared on the HA ESPHome screen. Maybe this is not as it’s supposed to be, but it works for me.

You can use it for logging, coding and xaml proofing too