Cannot make service calls to working ESPHome device

I have an esp32 in my bathroom that controls the under-cabinet LEDs, as well as a DHT11 temp/humidity sensor. This has been working fine for several weeks now. Over the past few nights though, It seems to have lost its connection to HA. Whenever I click on the wireless logs button of the device in ESPHome, it shows that the DHT11 is working and reading new values. However, whenever I try to toggle the LEDs from HA, I get a little error popup that says “Failed to call service light/turn_off. connection lost”. Additionally, the DHT11 readings are not being pushed to HA. A hard reboot did not make a difference.

This is what the logs show

    [547679605840] Not connected to master-bath-led-controller @ 192.168.20.11!
    [547074750736] Not connected to master-bath-led-controller @ 192.168.20.11!
    [547074274064] Not connected to master-bath-led-controller @ 192.168.20.11!
    [547239914768] Not connected to master-bath-led-controller @ 192.168.20.11!
    [547074732496] Not connected to master-bath-led-controller @ 192.168.20.11!

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1965, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2005, in _execute_service
    return await cast(
           ^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 848, in entity_service_call
    response_data = task.result()  # pop exception if have
                    ^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1192, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 892, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 593, in async_handle_light_off_service
    await light.async_turn_off(**filter_turn_off_params(light, params))
  File "/usr/src/homeassistant/homeassistant/components/esphome/light.py", line 290, in async_turn_off
    await self._client.light_command(**data)
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 1058, in light_command
    self._check_authenticated()
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 328, in _check_authenticated
    self._check_connected()
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 320, in _check_connected
    raise APIConnectionError(f"Not connected to {self._log_name}!")
aioesphomeapi.core.APIConnectionError: Not connected to master-bath-led-controller @ 192.168.20.11!

The logs suggest that the device is not connected. So going from that you can check 2 things:

  1. Ping the IP address from your computer to see if its actually there and responds to the ping command.
  2. In ESPHome, does it show offline or online?

The device is successfully connected to my wifi, and I can ping it. The device also shows as online.

Did you try to re-install it via ESPHome (option wireless)?

Okay I got it working, but only by physically reflashing the device. Weird.