ESPHome is Giving a 502: bad gateway error FIXED

As a preface, I am new to Home Assistant as well as esphome. I have HA installed on a raspberry pi 3b that was lying around. The rpi is currently connected to ethernet due to it having a broken wireless adapter. I installed ESPHome through the supervisor and enabled the sidebar option but when I open it, it gives me a 502 error. I have tried changing the port in the configuration with no success but I am unsure if I did it correctly. I’ve looked at other posters that have had my issue but they don’t seem to find a fix I understand. Any help would be appreciated. Sorry if there’s something obvious about HA that I don’t know yet.

UPDATE:

The issue seems to have been fixed by an “update”. The author reverted back to version 2021.12.1 which has been working fine for me. Thank you for responding and for all your help.

[19:56:33] INFO: Starting ESPHome dashboard...
Traceback (most recent call last):
  File "/usr/bin/esphome", line 33, in <module>
    sys.exit(load_entry_point('esphome', 'console_scripts', 'esphome')())
  File "/usr/bin/esphome", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.9/importlib/metadata.py", line 524, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.9/importlib/metadata.py", line 187, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: esphome

i updated to the most recent version of ESPHome earlier today and now I have the 502 error as well. Above are the logs from the ESPHome add-on. I’ve tried restarting the add-on, reinstalling, restarting Home Assistant and that’s about the extent of my abilities, hopefully someone can help.

Similar problem here…

Installed the latest version earlier today and now get the 502 error.

i restored a backup from before I updated ESPhome and everything is working again.

Version 2021.12.2 gives me the 502 error.
Version 2021.12.1 works without issue (for me)

Just today 2021.12.4 came out. Try with this update if it solves a problem. I have no problems here with 2021.12.2, but i don’t have HA on Pi…

Having same problem after updating to 2021.12.4 (running HAOS on VM).

21-12-21 06:58:36 INFO (MainThread) [supervisor.backups.manager] Creating new partial backup with slug b5eacf5f
21-12-21 06:58:36 INFO (MainThread) [supervisor.backups.manager] Backing up b5eacf5f store Add-ons
21-12-21 06:58:36 INFO (MainThread) [supervisor.addons.addon] Building backup for add-on a0d7b954_esphome
21-12-21 06:58:36 INFO (MainThread) [supervisor.addons.addon] Finish backup for addon a0d7b954_esphome
21-12-21 06:58:36 INFO (MainThread) [supervisor.backups.manager] Creating partial backup with slug b5eacf5f completed
21-12-21 06:58:36 INFO (SyncWorker_4) [supervisor.docker.interface] Updating image esphome/esphome-hassio-amd64:2021.12.1 to esphome/esphome-hassio-amd64:2021.12.2
21-12-21 06:58:36 INFO (SyncWorker_4) [supervisor.docker.interface] Downloading docker image esphome/esphome-hassio-amd64 with tag 2021.12.2.
21-12-21 06:58:41 INFO (SyncWorker_4) [supervisor.docker.interface] Stopping addon_a0d7b954_esphome application
21-12-21 06:58:42 INFO (SyncWorker_4) [supervisor.docker.interface] Cleaning addon_a0d7b954_esphome application
21-12-21 06:58:43 INFO (MainThread) [supervisor.addons] Add-on 'a0d7b954_esphome' successfully updated
21-12-21 06:58:43 INFO (SyncWorker_2) [supervisor.docker.interface] Cleanup images: ['esphome/esphome-hassio-amd64:2021.12.1']
21-12-21 06:58:43 INFO (SyncWorker_0) [supervisor.docker.addon] Starting Docker add-on esphome/esphome-hassio-amd64 with version 2021.12.2
21-12-21 06:58:47 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]
21-12-21 06:58:56 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]
21-12-21 06:58:57 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]
21-12-21 06:59:02 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]
21-12-21 06:59:04 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]
21-12-21 06:59:06 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]
21-12-21 06:59:07 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]
21-12-21 06:59:08 INFO (MainThread) [supervisor.updater] Fetching update data from https://version.home-assistant.io/stable.json
21-12-21 06:59:08 ERROR (MainThread) [supervisor.api.ingress] Ingress error: Cannot connect to host 172.30.32.1:64583 ssl:default [Connect call failed ('172.30.32.1', 64583)]

Have the same problem here
HA 2021.12.4
ESPHome 2021.12.2

Bad Gateway 502

Restore of ESPHome 2021.12.1 works

Well, i spoke too soon…
First, i messed up… i guess OP was talking for ESPHome version, not HA… but, still, my statement "it works " was for HA2021.12.2, like i said above. Now i just updated to 2021.12.4 and it won’t open…nothing happens, just blank screen. ESPHome version is 2021.12.2.
ESPHome log is:

importlib.metadata.PackageNotFoundError: esphome
[07:13:36] INFO: Starting ESPHome dashboard...
Traceback (most recent call last):
  File "/usr/bin/esphome", line 33, in <module>
    sys.exit(load_entry_point('esphome', 'console_scripts', 'esphome')())
  File "/usr/bin/esphome", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/lib/python3.9/importlib/metadata.py", line 524, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.9/importlib/metadata.py", line 187, in from_name
    raise PackageNotFoundError(name)

There is a github issue in for it. Problem with the docker image. Jesse is working on it.

Yeah, well. that happens without having my morning coffee first…
i just noticed that with HA update to 2021.12.4 my ESPHome also updated from 2021.12.1 to 2021.12.2… oh, well…

EDIT: restore fo ESPHome 2021.12.1 solves the problem, BTW…

Had the same problem, thank god backups are done automatically as part of the upgrade process.

Seems the version has been withdrawn on supervisor and we´re able to go back to 2021.12.1. Swift response from Jesse! :+1:

sorry the stupid Q, found it. Never thought that it is so easy / HA so mature, I tip my hat to all those that made it possible.

Looks like 2021.12.2 has been withdrawn. You should find the “update” offer to 2021.12.1 in your HA Configuration section shortly.

I’m on 2021.12.3 now, but I have the same issues as above. How can I go back to 2021.12.1?

(all the current devices work and can be edited although they seem offline. Adding a new device is not possible, because it keeps initializing)

Had the same issue today even after shutting down and starting up again.

It fixed itself when I chose rebuild

I switched to Nginx Proxy Manager from Caddy and not I’m getting 502: Bad Gateway on ESPHome.
I stopped Nginx Proxy Manager but the error continues.
Even stranger is, I’m getting the following from the ESPHome add-on logs:

[14:19:00] INFO: Waiting for dashboard to come up...
[14:19:00] INFO: Starting NGINX...
nginx: [emerg] invalid port in ":" of the "listen" directive in /etc/nginx/servers/ingress.conf:2
[14:19:01] INFO: Waiting for dashboard to come up...
[14:19:01] INFO: Starting NGINX...
nginx: [emerg] invalid port in ":" of the "listen" directive in /etc/nginx/servers/ingress.conf:2
[14:19:02] INFO: Waiting for dashboard to come up...
[14:19:02] INFO: Starting NGINX...
nginx: [emerg] invalid port in ":" of the "listen" directive in /etc/nginx/servers/ingress.conf:2
[14:19:03] INFO: Waiting for dashboard to come up...
[14:19:03] INFO: Starting NGINX...
nginx: [emerg] invalid port in ":" of the "listen" directive in /etc/nginx/servers/ingress.conf:2

The problem is not fixed.

Does anyone have a solution to this problem?

Home Assistant 2022.9.7
Supervisor 2022.09.1
Operating System 9.0
Frontend 20220907.2 - latest
ESPHome Current version: 2022.9.2 

I seems like it just needed a reboot.
502: bad gateway error is no more.

Where chose rebuild?

ESPHome home page → three vertical dots of your project → select “clean build files”.
When you get an error of any kind (in general) then always do this first - in many cases it helps. (like version update, going from arduino to esp-idf or reverse… in such cases some kind of errors are often shown).