Home Assistant can't see the ESPHome entities

Any guess why Home Assistant can’t see the ESPHome entities for this device?

I have a PIR on a Sonoff Basic that has been working for a couple of years.
And yesterday it stopped working. Coincident, possibly, with my router replacement, but
I don’t see how.

I have in the yaml code:

  port: 80

From the web page I can turn the relay on and off.
And I can see the PIR going on and off when someone walks into the PIR range.
I re-flashed the ESP OTA- no problem.

But, I can’t see the entities in Home Assistant and the automation to turn on
the relay for a few minutes won’t trigger.

Unless someone has a better idea, I can delete the device and start over with a new discovery, then fix the “_2” mess in the automation.

Here is my device yaml file:

## closet.pir ##
# Sonoff Basic in my office closet with a PIR sensor on GPIO14

  device_name: closet-pir
  friendly_name: closet_pir

  wifi: !include common/wifi.yaml
  device_base: !include common/esp8266.yaml

  port: 80

  - platform: gpio
    name: ${friendly_name} Relay
      number: GPIO12
      mode: output
    id: relay

  - platform: restart
    name: ${friendly_name} Restart

  - platform: gpio
    name: ${friendly_name} LED
      number: GPIO13
      mode: output
      inverted: True
    id: led    

  - platform: gpio
      number: GPIO14    # PIR Sensor
      inverted: False
      #mode: INPUT_PULLUP
    name: ${friendly_name} PIR
    device_class: motion
    # Turn on the LED when the PIR detects motion.
      - switch.turn_on: led
      - switch.turn_off: led

  # Get the uptime    
  - platform: template
    name: ${friendly_name} Uptime
    id: uptime_human
    icon: mdi:clock-start

  # Uptime sensor.
  - platform: uptime
    name: ${friendly_name} Uptime Epoch
  - platform: uptime
    name: ${friendly_name} Human Uptime Sensor
    id: uptime_sensor
    update_interval: 60s
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + "d " : "") +
                (hours ? String(hours) + "h " : "") +
                (minutes ? String(minutes) + "m " : "")

Remove it from HA and re-add it.

I figured as much, but I was hoping to avoid the _2 mess that Home Assistant makes of my entities.

Remove it. Restart HA. Re-add it. That will guarantee the original entities are gone avoiding the _2 issue.

Done. It worked. I was certain that this would have made a whole bunch of _2 entities… But it didn’t.

It shouldn’t. It shouldn’t even more with recent updates. The restart is not strictly necessary but is cheap insurance to make sure the previous entities were deleted.

It’s other way around: these _2 entities are created if you don’t remove device and HA in some way thinks it’s a different device, so created entities with same name, but _2 addition… but if you delete device first then all entities from that device are deleted anyway, so there’s no need for _2

In fact, when i “tinker” with some esp device (like add, change, remove entities) i always delete and re-add device at the end, to prevent _2 and non-existing (changed, removed) entities.