ESPHome device added, shows green in the dashboard, but devices now show unavailable

I flashed and added a ESPHome fan control switch. In the ESPHome panel, it shows green and I can see logs from it. The actual HA devices used to work, but have been showing unavailable for the last 2 days.

What might have happened here?

Check the debug logs for the device in ESPHome.

I just turned on debugging. I see it sending data in the logs. The only error I see is one that the notes from esphome-devices say I can ignore. What should I be looking for?

Messages relating to the API.

e.g. here’s one of mine that keeps intermittently dropping off the network:

ERROR Error while reading incoming messages: Error while receiving data: [Errno 104] Connection reset by peer
WARNING Disconnected from API: Error while receiving data: [Errno 104] Connection reset by peer
INFO Connecting to 10.1.1.196:6053 (10.1.1.196)
WARNING Couldn't connect to API (Timeout while waiting for message response!). Trying to reconnect in 1 seconds
INFO Connecting to 10.1.1.196:6053 (10.1.1.196)
INFO Successfully connected to 10.1.1.196

The other 41 ESPs have a rock solid connection. Still trying to get to the bottom of it.

If you power cycle the device you should see an API connection being made.

I don’t see anything obvious here. I toggled the breaker and left the log up.

[09:27:48][D][sensor:099]: 'Lanai Fans Wifi Signal': Sending state -64.00000 dBm with 0 decimals of accuracy
WARNING Disconnected from API: Timeout while waiting for message response!
INFO Connecting to lanai_fans.local:6053 (192.168.1.116)
INFO Successfully connected to lanai_fans.local
[09:28:28][C][tuya:025]: Tuya:
[09:28:28][C][tuya:034]:   Datapoint 9: switch (value: OFF)
[09:28:28][C][tuya:036]:   Datapoint 105: int value (value: 100)
[09:28:28][C][tuya:036]:   Datapoint 10: int value (value: 99)
[09:28:28][C][tuya:034]:   Datapoint 1: switch (value: OFF)
[09:28:28][C][tuya:040]:   Datapoint 3: enum (value: 0)
[09:28:28][C][tuya:040]:   Datapoint 106: enum (value: 0)
[09:28:28][C][tuya:036]:   Datapoint 101: int value (value: 0)
[09:28:28][C][tuya:036]:   Datapoint 103: int value (value: 0)
[09:28:28][C][tuya:050]:   Product: '{"p":"ipyqwvhvzzjezv35","v":"3.3.14","m":0}'
[09:28:28][E][uart:050]:   Invalid baud_rate: Integration requested baud_rate 9600 but you have 115200!
[09:28:51][D][sensor:099]: 'Lanai Fans uptime': Sending state 34.15700 s with 0 decimals of accuracy
[09:29:18][D][sensor:099]: 'Lanai Fans Wifi Signal': Sending state -61.00000 dBm with 0 decimals of accuracy
[09:29:51][D][sensor:099]: 'Lanai Fans uptime': Sending state 94.15700 s with 0 decimals of accuracy
[09:30:18][D][sensor:099]: 'Lanai Fans Wifi Signal': Sending state -62.00000 dBm with 0 decimals of accuracy
[09:30:51][D][sensor:099]: 'Lanai Fans uptime': Sending state 154.15700 s with 0 decimals of accuracy
[09:31:18][D][sensor:099]: 'Lanai Fans Wifi Signal': Sending state -61.00000 dBm with 0 decimals of accuracy
[09:31:51][D][sensor:099]: 'Lanai Fans uptime': Sending state 214.15700 s with 0 decimals of accuracy
[09:32:18][D][sensor:099]: 'Lanai Fans Wifi Signal': Sending state -61.00000 dBm with 0 decimals of accuracy
[09:32:51][D][sensor:099]: 'Lanai Fans uptime': Sending state 274.15799 s with 0 decimals of accuracy
[09:33:17][I][ota:046]: Boot seems successful, resetting boot loop counter.
[09:33:18][D][sensor:099]: 'Lanai Fans Wifi Signal': Sending state -62.00000 dBm with 0 decimals of accuracy

What about the Home assistant system log?

Could this be it? Whatever it is, it seems not good.

Logger: engineio.client
Source: /usr/local/lib/python3.8/site-packages/engineio/asyncio_client.py:559
First occurred: June 7, 2021, 4:32:15 AM (2246 occurrences)
Last logged: 9:42:42 AM

packet queue is empty, aborting

Do you use Ambient Weather?

Yep! Well crap, that isn’t it.

Have a look at the ESPHome integration in Configuration / Integrations / ESPHome / Your Device / Entities

Are there a bunch of entities with _2 added on the end?

Nope. No duplicates.

edit: Would removing the whole thing and trying again help at all?

Save the text of the sketch you use to compile, if that is lost there is no way to recover it from the esp. Disconnect the esp, remove the iteration in integrations, and then in the .storage folder of your HA installation there will be a copy of the esp config.

However it will not have the same name. You’ll have to open the text files and examine the contents to find it. Then delete it and restart HA and power up the node. If not you’re likely to wind up with copied entities with a _2 suffix.

Hmmm. This is in a wall switch. Does this mean I’ll need to pull the switch and reflash it manually?

No you dont need to change anything on the esp. These are the config files in home assistant. This is just to remove and reinstall it.

Oh, maybe I see the issue now. You mentioned this earlier @tom_l and I missed it. In the HA logs, I found this:

Can't connect to ESPHome API for lanai_fans (192.168.1.108)

But it’s real IP is .116 right now. Does ESPHome require a static IP?

It can use mDNS but yes it is best to use a static ip. Assign one then delete and re-add the ESP device in Configuration / Integrations.

ESPHome can clearly connect to it via mDNS, but are you sure HA can? That error seems to indicate that its only using the discovered IP address.

Did you restart Home Assistant?

I have dozens of ESP devices- ALL of them use dynamic IP. As I move my devices from Tasmota to ESPHome, they are still dynamic. I have never had an IP problem.

I don’t set static IP on any of my devices, just my servers.

Look in Developer Tools → States and search for your entities there. I don’t understand why but when I change the code and do another upload, I sometimes get a _2 suffix on the entity. Not always, just sometimes.

wtf. I now have a device with a _2. I swear to God that wasn’t there before. What do I do?

I wish I knew WHY this happens. As I said, it seems to be random. Until someone can explain why, I just edit my /config/ui-lovelace.yaml file and update the entities.