ESPHome with MQTT autodiscovery

Hey,

I am relatively new to ESPHome and HA, but I have recently been trying to setup my system.

I went for MQTT way, i.e. my ESP8266s do not have API tag in their config. I managed to setup ESP8266 and MQTT explorer shows the device and messages coming in. I also see retained configuration messages of homeassistant with its prefix topic. This is my device config.

esphome:
  name: esp8266-1
  friendly_name: scd4x-air-quality-1

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
#api:

sensor:
  - platform: scd4x
    co2:
      name: "co2"
    temperature:
      name: "temp"
    humidity:
      name: "humidity"
    i2c_id: bus_a  

i2c:
  sda: 2
  scl: 14
  scan: true
  id: bus_a

mqtt:
  broker: IP
  username: user
  password: user

ota:
  
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

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

captive_portal:

One problem I saw right away is that no entities were created in homeassistant although retained config messages are seen in MQTT explorer.

image

Do I need additional setup for HA to see this device and somehow to autodetect it and add entities? Do I have to modify configuration.yaml to do that only? What is the typical workflow for MQTT ESPHome devices/entities to appear? I have reviewed manual several times, but it is really hard to read and understand sometimes, because it mostly works as a reference only…

Moreover, I recently reinstalled homeassistant machine and thus all of my devices are gone now. But I do not understand, how can I readd my devices to ESPHome dashboard that are based on MQTT integration only? They do not have API integration. At the moment, HA does not add them via devices section (with an IP) and states that “it does not have API tag”. Also, there is no option to readd on ESPHome section. I am simply lost, I do not want to reflash all my devices incase I reinstall homeassistant OS…

Thank you.

Is MQTT added as an integration here Open your Home Assistant instance and show your integrations.

And is Discovery enabled in the same place?

I do not know, why I missed that, but yes, I found that there is that MQTT autodiscovery option that I should have enabled. For some reason I was not aware of this… Thanks, now it seems that entities are created, appreciate that.

But still, the second problem exists. I do not know how to readd that device to ESPHome dashboard in order to enable OTA upgrades. Adding device through HA simply requires API, but… in this case, it is not preset.

Do you have any ideas?

Thanks.

So you ghave the ESPHome add-on installed but did not use it to create the device?

I have addon installed. I added ESPHome device, configured it successfully, I was able to install firmware OTA, but then I deleted the device. And I am no longer able to add it back. It does not have API enabled, only MQTT works for data transfer, so I am not really sure how to get it back to ESP Dashboard (if that is possible at all) without actually reflashing from scratch.

If that’s the yaml for it above, create a new device with the same name as the existing. Before saving copy & paste that code into it.

It should then be fine - you don’t need to reflash.

if you ever lose the yaml code for a device that isn’t on the dashboard - it’s gone forever. It is in no way recoverable from the device.

1 Like

Thanks, I will give it a try this evening. Appreciate your help.