Esp8266 device show Online status in Esphome but actually is offline

As the topic says.
One other device, the same config does show this problem. I did try to enable “Use ping for status” in ESPHome Device Builder config
But it does not help. Any suggestions?

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

ota:
  - platform: esphome
    password: "xxxx"

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

  manual_ip:
    static_ip: 192.168.x.x
    gateway: 192.168.x.x
    subnet: 255.255.255.0  

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

captive_portal:

sensor: 
  - platform: wifi_signal
    name: "WiFi Signal"
    id: su
    update_interval: 120s
    filters:
      - sliding_window_moving_average:
          window_size: 3
          send_every: 2
          send_first_at: 1 
    icon: mdi:wifi

mqtt:
  topic_prefix: su
  broker: 192.168.x.x
  username: xxxx
  password: xxxx
  discovery_prefix: homeassistant
  discovery: True
  discover_ip: True
  log_topic: error     

switch:
  - platform: gpio
    pin: GPIO4
    name: "su connected LED"
    id: led

What is your definition to “offline”. Your router doesn’t see it and there’s no ap?

@Karosm:
Ping returns: Destination host unreachable.
And MQTT says sensor is Unavailable.
But ESPhome says Online after about 5min the sensor was turned off.

When I checked 3 hours later Esphome says Offline.
How much time expected between Ping: "Destination host unreachable. " and
Esphome reporting : Offline?

I do not know what the timeout is, but you need to consider that some devices might be battery powered and in sleep mode, which means they might not reply to ping, but still be “alive”, just not awake, and can should therefore maybe not be marked as offline.

If you look at the Z-Wave, Zigbee and Thread integrations, then they typically have two timeouts.
One for mains powered devices that are usually minutes or maybe hours (mains powered devices can sleep too or there can just be momentary network issues) and another one for battery powered devices that are several hours long.

I do not think ESPHome have this distinction, so both situations might have to be covered in one timeout value.

Yes, It was considered, as I have multiple devices that configured for sleep and behave as you described. Still I thought the “Ping for status” should return host unreachable and switch status in Esphome to Offline? Also I see inconsistency in two sensors that run the same yaml (of course naming and all that is different).