After re-configuring ESPHome, MQTT Sensor goes offline

(Mods, I thought configuration was most appropriate, but please move this to ESPHome if you think it belongs there.)

So as the title says, I had a sensor communicating via MQTT that was online and working and suddenly stopped working when I installed ESPHome. After uninstalling and re-installing my integrations and add-ons, I come once again to the forum to seek help. Here’s the order of events:

  • Installed ESPHome to work with a atmospheric sensor for a room. It gets setup and works perfectly, except I need it to do something I’ve written in C++ and can’t get it to communicate to HA while also doing the fancy light tricks. (well maybe I could, but I didn’t want to learn what was needed in yaml just yet).
  • I uninstall/disable ESPHome once I realize I’m not using it for the time being. The three sensors still show up as unavailable in entities and I can’t delete them. I shrug it off as nbd.
  • Setup MQTT instead. Huzzah it works! It does both communicating with HA and fancy light tricks. This was 2-3 days ago.
  • Today, I’m working on a new project and I need ESPHome again. I enable it again.
  • The MQTT Sensors appear unavailable, but I didn’t connect it to me turning on the ESPHome yet, I figured it was a weird glitch and I put it on the list to take care of later.
  • Huzzah! ESPHome project works. MQTT is still unavailable.
  • The entities for the MQTT sensor are still present, but offline. I one-by-one uninstall items to try and figure it out.
  • I figured there was some cross talk because perhaps the device ID was used for a 2 separate integrations and HA didn’t know what to do with it. Since the old entities are still on the list but unavailable, I tackle getting rid of them first. Nothing got rid of them until I fully removed the integration and add-on of ESPHome. When I brought it back online the old entity was no longer there - a good sign. But the new one still wasn’t showing up either.
  • So I go through removing and reinstalling MQTT (mosquitto) in add-ons and integrations. Brought everything back online with the correct username and password - still nothing in entities.
  • (It should be noted that on the first installation where it worked, I didn’t need to add anything in my config.yaml file except for “mqtt, broker, port, username, pass”. I am also giving ample time (1-1.5 hours) between checking if the entity is there (incase it takes time) and also refreshing HA.)
  • Since it isn’t showing up I decide to add “sensor, - platform: mqtt, etc etc” to my configuration file. Still nothing.
  • And now I’m just making minor adjustments to the mqtt/sensor section of my configuration file, thinking it’s a syntax type error (though the HA IDE doesn’t throw any errors.)

I’ve checked the logs. The IP of that esp8266 is successfully connected. I listened in from HA/MQTT as well as MQTT explorer, and messages are being broadcast on the correct topic successfully from the esp8266. The messages are in the correct json format. I’ve attached two screenshots.

So now I’m wondering if my 1-1.5 hours of patience in between changes in the backend isn’t patient enough. I’m hoping in 6 hours the entities will show up. I just can’t figure out what else needs to be done for HA to add and recognize the sensor. I’m down to wondering if my indentations are wrong in my config file or something minor that I’ve overlooked! Passwords, usernames, IP addresses, ports, topics, etc - they are all how they should be.

What’s crazy is when I first setup this sensor via MQTT it was almost flawless. HA started listening, added the sensors, and I was in business with graphs on my dashboard. Let me know if I missed anything! I guarantee it is going to be a simple, minor change…


ESPHome does not send discovery messages when using mqtt. You will have to manually define the mqtt sensors in yaml.

Give the ESPHome api one more try though. It has always worked flawlessly for me and is a lot easier to manage than mqtt.

If you want to do this, comment out the mqtt setting in your device ESPHome config, add the api config and re-upload. Within 5 minutes or so Home Assistant should discover the device (you can force tis with a Home Assistant restart) and ask you to add the integration.

Thanks, Tom. Although I think I either don’t understand your suggestion or, more likely, I didn’t explain it well enough. I have 3 esp8266’s at home.

A: attached to a temp/hum/pres sensor along with 3 neopixels. I want this one to transmit the temp/hum/pres to HA while also changing the colors of the neopixels in the room. I tried including an “.h” file in the config and in the ESPHome yaml file, but I am woefully unskilled at creating classes and this method didn’t work well for me. So I removed device A from ESPHome. This is now This was communicating via MQTT broker in HA until I started up ESPhome again to add devices B and C.

B: Esp8266 in ESPHome that has 2 LEDs on it. The lights turn on/off via buttons in my dashboard and/or physical buttons on my other esp8266 (device C).

C: Same as above, but with buttons.

And where I am at now, I can’t get device A to appear in HA. It communicates messages successfully if I temporarily listen in on the topic, but other than that, I can’t seem to get the device to show up.

If you’re suggesting putting device A back into ESPHome - I would love to! I agree that it truly does work flawlessly. But I’m afraid the learning curve feels steep to take the rest of my arduino IDE code and translate it into HA format so that ESPHome can interpret and use it. Perhaps I misunderstood the whole creation of classes steps with ESPHome and there is an easier way to get the code in there to work? Happy to share the code, but it is essentially a declaration of a bunch of colors (10 per neopixel/sensor reading) and then a bunch of if/else if statements to change the neopixel color based on the temperature. Not rocket science, but again, I felt a bit lost getting this into ESPHome.

If you have renamed “device A” and try to use the ESPHome api you may see messages along the lines of “device does not produce a unique id” in your system log. This will require some .storage editing to fix.

1 Like

@tom_I - thank you for this response! Because of this and another comment on a thread where you suggested looking in the .storage folder, I did just that today. I tried limiting my esp files by time, but it wasn’t totally clear which ones were attributed to which device. Either way, I ended up removing all files from the folder. Within a few minutes, not only were my ESPNow devices up and communicating well but my esp8266 sending temp via MQTT was working perfectly as well. Everything is now up and running smoothly. Thank you!!! Seriously, that was very insightful.

1 Like